﻿package Server.Poker.NiuNiu10;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;

import Server.Agent.GameAgent;
import Server.Agent.GameConfig;
import Server.Agent.GameDB;
import Server.Model.Base.IRoom;
import Server.Model.Base.IServerUserItem;
import Server.Model.Base.SHMUser;
import Server.Model.Base.SecShmUser;
import Server.Model.Base.UserGoldChange;
import Server.Model.Base.UserRmbChange;
import Server.Model.Hall.QpGameMgr;
import Server.Model.Hall.dthall;
import club.ClubMgr;
import club.ClubRedis;
import common.routine.CommonDef;
import common.routine.PublishDef;
import redis.protocal.DbInfoMgr;
import redis.protocal.DwcRedisRecord;
import redis.protocal.UserRedisInfo;
import robot.GoldMgr;
import robot.Robot;
import robot.RobotMgr;
import Server.Poker.Replay.*;
import admin.AdminRedis;

//牛牛每一局的战绩
class NNRoundRecord {
		// 战绩记录
		public int m_vecReport_CardData [][] = new int[10][5]; // 卡牌牌值
		public int m_vecReport_CardType[] = new int[10];  	  // 牌型
		public double m_vecReport_Score[] = new double[10];		  // 分数
		public int m_vecReport_XiaZhu[] = new int[10]; 		  // 下注数
		public int m_vecReport_Zhunag = 0;					  // 庄家
		public String[] m_names = new String[10]; 
};
	
	
public class niuniuTable10 extends IRoom {
	public Replay Replay = new Replay();
	@Override
	public int GetID() {
		return m_dwTableID;
	};

	@Override
	public int GetCreator() {
		return m_Creator;
	}
	@Override
	public String GetType() {
		return "NIUNIU10";
	};
	@Override
	public void OnClientClose(int uid) {
		System.out.printf("%n--- NIUNIU LOG : tableId: %d -- user: %d OnClientClose %n wanfa: %s",m_dwTableID,uid,m_strParam);
		OnUserStandUp(uid,false);
	};

	public boolean SendData(int wChairID, String sData) {
		// 缇ゅ彂鐢ㄦ埛
		if (wChairID == Constants.INVALID_CHAIR) {
			for (short i = 0; i < m_pIUserItem.length; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					if (m_pIUserItem[i].isAndroidUser == 0) {
						dthall.getInstance().onSend(m_pIUserItem[i].dwUserID, sData);
					} else {
						// mPlayers[i].SendGameMessage(wSubCmdID, pData,
						// wDataSize, data);
					}
				}
			}

			return true;
		} else {
			if (wChairID >= m_pIUserItem.length) {
				dthall.getInstance().onSend(wChairID, sData);
			} else if (m_pIUserItem[wChairID].dwUserID > 0) {
				if (m_pIUserItem[wChairID].isAndroidUser == 0) {
					dthall.getInstance().onSend(m_pIUserItem[wChairID].dwUserID, sData);
				} else {
				}
				return true;
			}
		}

		return false;
	}

	int m_dwLastDoCmdTime;
	public int fangzhu;
	public int CanSit(int _Uid) {
		if(this.isDwcType()){
			UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(_Uid);
			if(info.json.optInt("userRmbType") == 1 && !canUserJoinRentRoom(info.json.optInt("upAgentUid"))){
				return 22;
			}else if(info.json.optInt("userRmbType") == 0 && m_clubOwnerId != 0){
				UserRedisInfo clubInfo = dthall.getInstance().getSafeUserRedisInfo(m_clubOwnerId);
				if(clubInfo.json.optInt("userRmbType") == 1){
					return 23;
				}
			}
		}
		if (m_Creator == _Uid) {
			return 14;
		}	

		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == _Uid) {
				SUBCMD_S_OnLine cmd = new SUBCMD_S_OnLine();
				cmd.uid = _Uid;
				cmd.seat = i;
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
				return i;
			}
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null && isZuJuType()) {
			if (m_payWay.equalsIgnoreCase("CLUBPAY") || m_payWay.equalsIgnoreCase("WINPAY")) {
				if(m_payWay.equalsIgnoreCase("CLUBPAY")){
					for (int i = 0; i < 4; i++) {
						if (m_pIUserItem[i].dwUserID == 0) {
							return i;
						}
					}
					return 12;
				}
				if (user.getGem(0) < m_byCostGem) {
					return 11;
				}
			}else{
				if (m_payWay.equalsIgnoreCase("AAPAY") )
				{
					if (user.getGem(0) < m_byCostGem) {
						return 11;
					}
				}
			}
		}
		if(user != null && isGoldType()){
			if(user.getCoin(0) < m_ruchang){
				return 21;
			}
		}
		if(user != null && isDwcType()){
			if(user.getRmb1v1Value() < m_ruchang){
				return 21;
			}
		}
		if (m_locked != 0) {
			return 13;// 已经开始 并且房主不让近
		}

		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntUser++;
			}
		}
		if (cntUser >= 10) {
			return 13;
		}
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				return i;
			}
		}
		return 10;
	};

	Long m_lStartTime;
	int needDealTime;
	int m_dwTableID;
	long m_dismissTimer;
	int maxPeople = 10;
	int m_byAgreeDismiss[] = new int[10];

	boolean m_bGameStarted;
	boolean m_bTableStarted;
	int m_byRound;
	int m_byMaxRound;
	int m_wFaPaiDelay; // 鍙戠墝寤惰繜
	int m_wRobotSeconds[] = new int[10]; // 绛夊緟鏃堕暱
	int m_nextUser = 0;//杞簞鏃剁殑涓嬩竴涓敤鎴


	int m_byQiangZhuang[] = new int[10]; // 鏄惁鎶㈠簞锛屽拰鎶㈠簞鐨勫嶇巼
	int m_byXiaZhu[] = new int[10]; // 姣忎釜浜虹殑涓嬫敞
	int m_byXuanNiu[] = new int[10]; // 姣忎釜浜虹殑涓嬫敞

	int m_wZhuangPower;// 褰撳墠搴勭殑鍊嶇巼
	int m_randBeiShu = 0;
	public int m_byCostGem;
	public int m_kouChuMode = 0;
	public int m_fdFen;
	public String m_payWay;
	public String m_betMode;	//缁忓吀鍊嶆暟銆345鍊嶃佺柉鐙10鍊
	public String m_scoreMode;	//算分模式(经典模式)
	public String m_xianshiMode;//鏄庣墝妯″紡銆佹殫鐗屾ā寮
	public String m_zhuangMode;//閫夊簞锛屾姠搴勶紝杞簞
	public String m_lunZhuangRule;
	public String m_guize;	   //瑙勫垯
	public Boolean m_bAutoConfigPai; // 自动配牌
	
	public String m_strParam;
	public String m_strRoomDesc;
	
	public String[] m_vecParam;
	
	public int m_byZhuang;// 褰撳墠搴勪綅缃
	public int m_vecWinScore[] = new int[10];
	public int m_vecLoseScore[] = new int[10];
	public int m_vecCardType[] = new int[10];
	public int m_vecRoundScore[] = new int[10];
	public int m_vecResultScore[] = new int[10];
	public double m_doubleVecResultScore[] = new double[10];
	public double m_doubleKouWinResultScore[] = new double[10];
	public int m_kouWinSumJu = 0;
	public int m_kouWinCurrJu = 0;
	public String m_vecInputWenZi;
	// 总结算统计

	// 通杀次数
	public int m_allWinArray[] = new int [10];

	// 通赔次数
	public int m_allFailArray[] = new int [10];

	// 牛牛次数
	public int m_niuNiuNumArray[] = new int [10];

	// 无牛次数
	public int m_noHaveNiuNumArray[] = new int [10];

	// 胜利次数
	public int m_winNumArray[] = new int [10];
	
	public int m_vecXuanPaiCardList[][] = new int[10][5];// 玩家选牌牌型
	
	public NNRoundRecord m_vecRoundRecord[] = new NNRoundRecord[88];
	
	GameLogic m_GameLogic = new GameLogic();
	String m_curStage;
	int m_bTableCardArray[][] = new int[10][5]; // 妗岄潰鎵戝厠 //been 5
	
	int m_locked = 0;//榛樿鍏佽杩
	
	IServerUserItem m_pIUserItem[] = new IServerUserItem[10]; // 鐢ㄦ埛鎸囬拡
	{
		for (int i = 0; i < m_pIUserItem.length; i++) {
			m_pIUserItem[i] = new IServerUserItem();
		}
	}
	long m_LookOnUserID[] = new long[50]; // 瑙備紬

	public int m_Creator;// 鎴夸富
	public int m_createTime = 0;

	niuniuTable10() {
		m_bTableStarted = false;
		m_createTime = (int)(System.currentTimeMillis() / 1000);
		m_lStartTime = System.currentTimeMillis() / 1000;
		m_bRemove = false;
		m_byCostGem = 0;
		m_fdFen = 0;
		
		m_payWay = "FZPAY";
		m_betMode = "BETMODE0";
		
		m_xianshiMode = "MINGPAI";
		m_zhuangMode = "QIANGZHUANG";
		m_lunZhuangRule = "WUNIUXIAZHUANG";
		m_bAutoConfigPai = false;
		m_guize = "GUIZE_DEFAULT";
		
		m_strParam = "";
		m_strRoomDesc = "";
		
	}

	void Init(int cbReason) {
		m_dwLastDoCmdTime = 0;
		m_bGameStarted = false;
		m_wFaPaiDelay = 2;
		m_vecInputWenZi="";	
		for (int i = 0; i < 10; i++) {
			m_wRobotSeconds[i] = 0;
			m_byQiangZhuang[i] = 0;
			m_vecCardType[i] = 0;
			m_byXiaZhu[i] = 0;
			m_byXuanNiu[i] = 0;
			m_wZhuangPower = 1;
			m_vecRoundScore[i] = 0;
			
			for (int j = 0; j < 5; j++) {
				m_vecXuanPaiCardList[i][j] = 0;
			}
		}
		
		m_wZhuangPower = 1;
		
		if(m_zhuangMode.equalsIgnoreCase("QIANGZHUANG"))
		{
			m_byZhuang = 0;	
		}
		
		switch (cbReason) {
		case Constants.INIT_TOTAL: {
			
			m_dismissTimer = 0;
			m_byAgreeDismiss[0] = 0;
			m_byAgreeDismiss[1] = 0;
			m_byAgreeDismiss[2] = 0;
			m_byAgreeDismiss[3] = 0;
			m_byAgreeDismiss[4] = 0;
			m_byAgreeDismiss[5] = 0;
			m_byAgreeDismiss[6] = 0;
			m_byAgreeDismiss[7] = 0;
			m_byAgreeDismiss[8] = 0;
			m_byAgreeDismiss[9] = 0;
			Constants.memset(m_LookOnUserID, 0, Constants.sizeof(m_LookOnUserID)); //
			m_byRound = 0;
			m_byMaxRound = 0;
			m_byZhuang = 0;
			for (int i = 0; i < 10; i++) {
				m_vecWinScore[i] = 0;
				m_vecLoseScore[i] = 0;
				m_vecResultScore[i] = 0;
				m_doubleVecResultScore[i] = 0;
			}
		}
			break;
		case Constants.INIT_FIRST_ROUND: {

		}
			break;
		case Constants.INIT_NEWROUND: {

		}
			break;
		}
	}

	void KickRobots() {
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
	}

	boolean HasRobot() {
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				return true;
			}
		}
		return false;
	}

	void SendAvatar(int _Uid) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}

		String iter = dthall.getInstance().Handle_OnGetUserAvatar(_Uid);

		SUBCMD_S_Avatar cmd = new SUBCMD_S_Avatar();
		cmd.m_lUid = _Uid;
		if (iter != null) {
			cmd.szAvatarURL = iter;
		} else {
			cmd.szAvatarURL = PublishDef.getDefaultHeadAvatar();
		}

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

	}
	public void SendLocationData(SHMUser user) {
		JSONObject data = new JSONObject();
		data.put("loc", user.getGpsLocInfo());
		data.put("uid", user.getUid());
		data.put("command", "GPS_LOC");
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if(other != null){
						data.put("uid", other.getUid());
						data.put("loc", other.getGpsLocInfo());
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}

	public void SendGpsData(SHMUser user) {
		JSONObject data = new JSONObject();
		List<Double> gpsData = user.getLocateInfo();
		data.put("lng", gpsData.get(0));
		data.put("lat", gpsData.get(1));
		data.put("command", "GPS_DATA");
		data.put("uid", user.getUid());
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if (other != null) {
						gpsData = other.getLocateInfo();
						data.put("uid", other.getUid());
						data.put("lng", gpsData.get(0));
						data.put("lat", gpsData.get(1));
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}
	public void OnUserSit(int _Uid) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 10) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null) {
			SendGpsData(user);
			SendLocationData(user);
		}
		if (user != null) {
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID == _Uid) {
					m_wRobotSeconds[i] = 0;
					m_pIUserItem[i].dwUserID = _Uid;
					// m_pIUserItem[i].lUserScore = user.getCoin();
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}
					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
					}
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();

					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_nState = m_pIUserItem[i].cbUserStatus;
					cmd.m_sCurStage = m_curStage;
					cmd.m_lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						cmd.m_lUserRmb = user.getRmb1v1Value();
					}
					
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					if (m_bGameStarted) {
						SendGameScene(_Uid, Constants.GS_PLAYING);
					} else {
						SendGameScene(_Uid, Constants.GS_FREE);
					}

					SendAvatar(m_pIUserItem[i].dwUserID);

					return;
				}
			}
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID == 0) {
					m_wRobotSeconds[i] = 0;
					m_pIUserItem[i].dwUserID = _Uid;
					m_pIUserItem[i].lUserScore = 0;
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}
					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
					}
					
					if(m_bTableStarted)
					{
						m_pIUserItem[i].cbUserStatus = Constants.US_LOOKON;
					}
					
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();
					// Constants.memset(&cmd, 0, Constants.sizeof(cmd));

					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_nState = m_pIUserItem[i].cbUserStatus;
					cmd.m_lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						cmd.m_lUserRmb = user.getRmb1v1Value();
					}

					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					if (m_bGameStarted) {
						SendGameScene(_Uid, Constants.GS_PLAYING);
					} else {
						SendGameScene(_Uid, Constants.GS_FREE);
					}

					return;
				}
			}
		}

		return;
	}

	int FindSeat(long _Uid) {
		for (int bySeatID = 0; bySeatID < 10; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}

	int GetPlayerCount() {
		int cntPlayer = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	int GetRobotCount() {
		int cntPlayer = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	@Override
	public void OnUserStandUp(int _Uid,boolean leaveroom) {
		int wChairID = FindSeat(_Uid);
		if(wChairID >= 10)
		{
			System.out.println("Erro wchairID: " + wChairID);
			return;
		}

		
		if(m_bTableStarted == true && this.isDwcType() && leaveroom == true){
			//真金情况可以退出
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			
			for(int i = 0; i < 10; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && _Uid != m_pIUserItem[i].dwUserID)
				{
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
			
			m_pIUserItem[wChairID].Init();
			QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			//检查是否全部是机器人
			int realCnt = 0;
			for(int i = 0; i < 10; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0)
				{
					realCnt++;
				}
			}
			if(realCnt == 0){
				OnEventGameEnd(0, Constants.GAME_END_DISMISS);
				return;
			}
			//是否全部准备好了
			{
				int cntReady = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
						cntReady++;
					}
				}
			
				int cntUser = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus != Constants.US_LOOKON) {
						cntUser++;
					}
				}
			
				if (cntReady == cntUser && cntReady > 1) {
					OnEventGameStart();
				}
			}
			return;
		}
		if((Constants.US_LOOKON ==  m_pIUserItem[wChairID].cbUserStatus) 
				|| (m_bTableStarted == false && wChairID != 0 && leaveroom == true)){
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			
			for(int i = 0; i < 10; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && _Uid != m_pIUserItem[i].dwUserID)
				{
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
			
			m_pIUserItem[wChairID].Init();
//			if(m_bTableStarted)
			{
				int cntReady = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
						cntReady++;
					}
				}
			
				int cntUser = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus != Constants.US_LOOKON) {
						cntUser++;
					}
				}
			
				if (cntReady == cntUser && cntReady > 1) {
					OnEventGameStart();
				}
			}
			
			if(Constants.US_LOOKON ==  m_pIUserItem[wChairID].cbUserStatus){
				QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			}
		}
		if ((Constants.US_LOOKON ==  m_pIUserItem[wChairID].cbUserStatus) || (m_bTableStarted == false && leaveroom == true)) {
			if (wChairID > 0 && wChairID < 10) {
				m_pIUserItem[wChairID].Init();
				QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			} else {
			}
		} else {
			if (wChairID >= 0 && wChairID < 10) {
				m_pIUserItem[wChairID].cbOnline = (int) Constants.US_OFFLINE;
			}
		}
	}
	public void SetParam(String szParam) {
		m_strParam = szParam;
		
		m_vecParam = m_strParam.split(";");
	}

	public void SetDesc(String szDesc) {
		m_strRoomDesc = szDesc;
	}
	boolean SendGameScene(int _Uid, int bGameStatus) {
		int wChairID = FindSeat(_Uid);
		if(wChairID >= 10)
		{
			return false;
		}
		if (m_strParam.length() > 0) {
			String tmpRoomDesc = m_strRoomDesc;
			
			SUBCMD_S_Param cmd = new SUBCMD_S_Param();
			cmd.m_dwTableID = m_dwTableID;
			cmd.szParam = m_strParam;
			cmd.szRoomDesc = tmpRoomDesc;
			if(this.isDwcType() && this.m_dwcKouYing != 0){
				cmd.dwcKouYingRate = m_dwcKouYingRate;
			}

			if(this.inHall()){
				cmd.m_kouYingJuShu = 0;
			}else{
				cmd.m_kouYingJuShu = GoldMgr.getInstance().getKouWinJuShuInClub();
			}
			SendData(_Uid, cmd.getJsonData());
		}		
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntUser++;
			}
		}

		{
			SUBCMD_S_Table cmd = new SUBCMD_S_Table();
			cmd.vecInputWenZi = m_vecInputWenZi;
			cmd.m_dwTableID = m_dwTableID;// 鎴块棿ID
			cmd.m_bGameStarted = m_bGameStarted ? 1 : 0;// 鏄惁寮濮
			cmd.m_bTableStarted = m_bTableStarted ? 1 : 0;// 鏄惁寮濮
			
			if(m_bTableStarted && !m_bGameStarted){
				cmd.m_byRound = m_byRound - 1;
			}else{
				cmd.m_byRound = m_byRound;
			}
			
			cmd.m_byMaxRound = m_byMaxRound;
			cmd.m_cntUser = cntUser;// 鐜╁
			cmd.m_cntLookon = 1;// 瑙備紬
			cmd.m_byZhuang = m_byZhuang;
			Constants.memset(cmd.m_seatInfo, 0, Constants.sizeof(cmd.m_seatInfo));

			for (int i = 0; i < 10; i++) {
				cmd.m_seatInfo[i].m_lUid = m_pIUserItem[i].dwUserID;// UID
				cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserScore;// COIN
				cmd.m_seatInfo[i].m_NickName = m_pIUserItem[i].szNickName;// NICKNAME
				cmd.m_seatInfo[i].m_iBetCoin = 0;//
				cmd.m_seatInfo[i].m_cbGender = m_pIUserItem[i].cbGender;
				cmd.m_seatInfo[i].m_iAvatar = m_pIUserItem[i].dwFaceID;//
				cmd.m_seatInfo[i].m_cbUserStatus = m_pIUserItem[i].cbUserStatus;// 鐢ㄦ埛鐘舵
				cmd.m_seatInfo[i].m_iVipLevel = m_pIUserItem[i].cbVipLevel;// VIP
																			// LEVEL
				cmd.m_seatInfo[i].m_iTitle = 0;// 绉板彿
				cmd.m_seatInfo[i].m_isLookon = 0;// 鏄惁瑙備紬
				cmd.m_seatInfo[i].szIP = m_pIUserItem[i].szIP;// NICKNAME
				cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserCoin;
				if(this.isDwcType()){
					cmd.m_seatInfo[i].m_iTotalRmb = m_pIUserItem[i].lUserRmb;
				}
			}

			SendData(_Uid, cmd.getJsonData());
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					SendAvatar(m_pIUserItem[i].dwUserID);
				}
			}
		}

		if (m_bTableStarted == true) {
			SUBCMD_S_STAGE cmd = new SUBCMD_S_STAGE();

			cmd.szStage = m_curStage;
			cmd.m_byZhuang = m_byZhuang;// 褰撳墠搴勪綅缃
			cmd.m_wZhuangPower = m_wZhuangPower;// 褰撳墠搴勭殑鍊嶇巼
			cmd.needDealTime = (int) needDealTime;
			for (int i = 0; i < 10; i++) {
				cmd.m_byQiangZhuang[i] = m_byQiangZhuang[i]; // 鏄惁鎶㈠簞锛屽拰鎶㈠簞鐨勫嶇巼
				cmd.m_byXiaZhu[i] = m_byXiaZhu[i]; // 姣忎釜浜虹殑涓嬫敞
				cmd.m_byXuanNiu[i] = m_byXuanNiu[i]; // 姣忎釜浜虹殑涓嬫敞

				cmd.m_vecCardType[i] = m_vecCardType[i];
				cmd.m_vecRoundScore[i] = m_vecRoundScore[i];
			}
			
			for(int i = 0; i < 10; i ++)
			{
				if(m_pIUserItem[i].dwUserID > 0)
				{
					int seat = FindSeat(m_pIUserItem[i].dwUserID);
					for (int k = 0; k < 5; k++) {
						
						if(0 != m_vecXuanPaiCardList[seat][k])
						{
							cmd.m_bTableCardArray[seat][k] = m_vecXuanPaiCardList[seat][k];
						}else{
							cmd.m_bTableCardArray[seat][k] = m_bTableCardArray[seat][k]; // 妗岄潰鎵戝厠
						}						
					}
				}
			}
			
			
			SendData(_Uid, cmd.getJsonData());

			for(int i = 0; i < m_vecRoundRecord.length; i ++)
				{
					if(null == m_vecRoundRecord[i]){
						continue;
					}
					
					SUBCMD_S_ROUND_RECORD cmd_Record = new SUBCMD_S_ROUND_RECORD();
					cmd_Record.m_vecRecordRoundPai = m_vecRoundRecord[i].m_vecReport_CardData;
					cmd_Record.m_vecRecordRoundScore = m_vecRoundRecord[i].m_vecReport_Score;
					cmd_Record.m_vecRecordRoundCardType = m_vecRoundRecord[i].m_vecReport_CardType;
					cmd_Record.m_vecRecordRoundXiazhu = m_vecRoundRecord[i].m_vecReport_XiaZhu;
					cmd_Record.m_nZhuang = m_vecRoundRecord[i].m_vecReport_Zhunag;
					cmd_Record.m_nRound = i;
					cmd_Record.m_name = m_vecRoundRecord[i].m_names;
					
					System.out.printf("%n--- NIUNIU LOG : tableId: %d wanfa: %s",m_dwTableID,m_strParam);
					String sData_record = cmd_Record.getJsonData();
					SendData(_Uid, sData_record);
				}
		}

		switch (bGameStatus) {
		case Constants.GS_FREE: // 绌洪棽鐘舵
		{
			// 鏋勯犳暟鎹

			return true;
		}
		case Constants.GS_PLAYING: // 娓告垙鐘舵
		{
			// 鏋勯犳暟鎹

			return true;
		}
		}

		return true;
	}
	int random(int iMin, int iMax){
		Random ra =new Random();
		return ra.nextInt(iMax-iMin) + iMin;
	}
	void FaPai_1() {
		m_bTableStarted = true;
		m_bGameStarted = true;

		m_curStage = "STAGE_FAPAI_1";

		m_kouWinSumJu = GoldMgr.getInstance().getKouWinJuShuInClub();
		if(m_zhuangMode.equalsIgnoreCase("LUNZHUANG") || m_zhuangMode.equalsIgnoreCase("DINGZHUANG"))
		{
			needDealTime = 0;	
		}else{
			needDealTime = Constants.TIME_QIANZHUANG;	
		}
		m_aiRobotDelay = CommonDef.getRandomInt(3);

		if (m_byRound == 0) {
			m_byRound = 1;
		}

		OnRoundInfoChange();
//		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,	//方块 A - K
//		0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,	//梅花 A - K
//		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,	//红桃 A - K
//		0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,	//黑桃 A - K
		
		int m_bTableCardArray1[] = new int[10*5];
		m_GameLogic.RandCardList(m_bTableCardArray1,m_bTableCardArray1.length ); //璁＄畻鏁扮粍鐨勪釜鏁
		
		// testArray
		 int testArary [] = {
				 0x1A, 0x1B, 0x0C, 0x0D, 0x01,
				 0x11, 0x12, 0x13, 0x14, 0x15,
				 0x04,0x14,0x24,0x06,0x16,
				 10,18,19,20,21,
				 10,18,19,20,21};
//		 m_bTableCardArray1 = testArary;
		 
		 for (int i = 0; i < m_bTableCardArray1.length; i++) {
			int x = i /5;
			int y = i %5;
			m_bTableCardArray[x][y] = m_bTableCardArray1[i];
		 }
		//群控操作
		boolean hasrobot = false;
		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			if(m_pIUserItem[i].isAndroidUser == 2){
				hasrobot = true;
				vecEmpty.add(i);
			}
		}
		int changeRobotIndex = -1;
		double rate = 3.0;
		if(this.isDwcType() && hasrobot && m_doubleDiFen >= GoldMgr.getInstance().getRobotRmbDiFenControl() 
				&& CommonDef.getRandomInt(100) < GoldMgr.getInstance().getRobotRmbDiFenControlRate_KaiPai()){
			//真金模式，有机器人么，底分超过控制，开始强制换牌
			changeRobotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
		}

		if(changeRobotIndex == -1 && hasrobot && GoldMgr.getInstance().getQunKongRev("NIUNIU",m_doubleDiFen) > 0){
			//分级控制
			changeRobotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
		}
		if((this.isGoldType() || this.isDwcType() || this.isZuJuType()) && (changeRobotIndex > 0 || CommonDef.getRandomInt(100) < m_qunKongRate * 100)){
			double wonRate[] = new double[10];
			boolean needAdjust = false;
			for(int i = 0;i < 10;i++){
				SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
				if(user != null && m_pIUserItem[i].cbUserStatus == Constants.US_READY){
					if(this.isGoldType())
						wonRate[i] = user.getUserGoldWonRate();
					else if(this.isDwcType()){
						wonRate[i] = user.getUserRmbWonRate();
						if(i == changeRobotIndex){
							wonRate[i] = rate;
						}
					}else if(this.isZuJuType())
						wonRate[i] = user.getUserZuJuWonRate();
					if(wonRate[i] <= m_qunKongMinTh || wonRate[i] >= m_qunKongMaxTh)
						needAdjust = true;
				}else{
					wonRate[i] = -10000;
				}
			}
			if(needAdjust){
				//需要群控处理,先对牌进行打分,在替换牌
				int paiScore[] = new int[10];
				int origPai[][] = new int[10][5];
				for(int i = 0;i < 10;i++){
					if( m_pIUserItem[i].cbUserStatus == Constants.US_READY){
						int byOutCardData[] = new int[5];
						paiScore[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						Constants.memcpy(origPai[i], m_bTableCardArray[i], 5);
					}else{
						paiScore[i] = -100000;
					}
				}
				//换牌
				for(int i = 0;i < 10;i++){
					if(paiScore[i] <= -100000)
						continue;
					int rateIndex = getRankIndex(wonRate,-100.0);
					wonRate[rateIndex] = -10000;
					int scoreIndex = getRankIndex(paiScore,-100);
					paiScore[scoreIndex] = -10000;
					Constants.memcpy(m_bTableCardArray[rateIndex], origPai[scoreIndex],5);
				}
			}
		}else if(m_kouChuMode == 1){
			//反向调控
			
		}
		
		SUBCMD_S_FaPai_1 cmd = new SUBCMD_S_FaPai_1();
		cmd.byRound = m_byRound;
		cmd.byMaxRound = m_byMaxRound;
		cmd.waitTime = needDealTime;
		for (int i = 0; i < 10; i++) {
			m_vecRoundScore[i] = 0;
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {

				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
				cmd.vecIsReady[i] = 1;
			} else {
				if(Constants.US_LOOKON !=  m_pIUserItem[i].cbUserStatus)
				{
					m_pIUserItem[i].cbUserStatus = Constants.US_NULL;
				}
				
				
				cmd.vecIsReady[i] = 0;
			}
		}

		if(m_xianshiMode.equalsIgnoreCase("MINGPAI"))
		{
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
					for (int k = 0; k < 4; k++) {
						cmd.byPai[k] = m_bTableCardArray[i][k];
					}
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
		}
		if(m_xianshiMode.equalsIgnoreCase("ANPAI"))
		{
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID > 0  && ( m_pIUserItem[i].cbUserStatus == Constants.US_PLAY || 
				m_pIUserItem[i].cbUserStatus == Constants.US_LOOKON )) {
					for (int k = 0; k < 5; k++) {
						cmd.byPai[k] = 0;
					}
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
		}

		//System.out.printf("%n--- NIUNIU LOG : tableId: %s msg: FaPai_1 %n wanfa: %s",m_dwTableID,m_strParam);

	}

	int getRankIndex(double[] score,double limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	int getRankIndex(int[] score,int limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	void FaPai_2() {
		m_curStage = "STAGE_FAPAI_2";
		needDealTime = Constants.TIME_PEIPAI;
		m_aiRobotDelay = CommonDef.getRandomInt(2);

		SUBCMD_S_FaPai_2 cmd = new SUBCMD_S_FaPai_2();
		cmd.waitTime = needDealTime;
		for (int i = 0; i < 10; i++) {
			m_vecRoundScore[i] = 0;
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {

				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
				cmd.vecIsReady[i] = 1;
			} else {
				// 旁观状态不能清空
				if(Constants.US_LOOKON !=  m_pIUserItem[i].cbUserStatus)
				{
					m_pIUserItem[i].cbUserStatus = Constants.US_NULL;
				}
				
				cmd.vecIsReady[i] = 0;
			}
		}

		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && ( m_pIUserItem[i].cbUserStatus == Constants.US_PLAY || 
				m_pIUserItem[i].cbUserStatus == Constants.US_LOOKON ) ) {

				cmd.byPai = m_bTableCardArray[i][4];
				for (int j = 0; j < 5; j++) {
					cmd.byHandPai[j] = m_bTableCardArray[i][j];
				}
				SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());

			}
		}

		System.out.printf("%n--- NIUNIU LOG : tableId: %s msg: FaPai_1 wanfa: %s",m_dwTableID,m_strParam);

	}

	void OnEventGameStart() {
		Init(Constants.INIT_NEWROUND);

		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				// 旁观者的状态不能清空
				//如果用户资金少于离场资金则成为观察则状态
				if(m_pIUserItem[i].cbUserStatus != Constants.US_READY && m_pIUserItem[i].lUserRmb < GoldMgr.getInstance().getNiuNiu10UnreadyLook(m_doubleLiChang)){
					m_pIUserItem[i].cbUserStatus = Constants.US_LOOKON;
				}else if(m_pIUserItem[i].cbUserStatus != Constants.US_READY && m_pIUserItem[i].lUserRmb < GoldMgr.getInstance().getNiuNiu10UnreadyLook(m_doubleLiChang))
				{
					m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
				}
				
			}
		}
		FaPai_1();
		m_bTableStarted = true;
		m_bGameStarted = true;
	}	
	public void DoDismissRoomByOverTime(){
		OnEventGameEnd(0, Constants.GAME_END_DISMISS);
	}
	void OnEventGameEnd(int bySeatID,int cbReason){
		if(isZuJuType()){
			OnEventGameEndZuJu(bySeatID,cbReason);
		}else if(isGoldType()){
			onEventGameEndGold(bySeatID,cbReason);
		}else if(isDwcType()){
			onEventGameEndDwc(bySeatID,cbReason);
		}
	}
	void onEventGameEndDwc(int bySeatID,int cbReason){
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 0;

		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				cntUser++;
			}
		}
		m_aiRobotDelay = (int) (4 + CommonDef.getRandomInt(3) + cntUser * 1);
		double shuishourate = getShuiShou(this.GetType());
		double shui = this.m_doubleDiFen * shuishourate;
		if(shui < 0.01){
			shui = 0.0;
		}
		double[] realshui = new double[10];
		double[] vecRoundScore = new double[10];
		for(int i = 0;i < 10;i++){
			realshui[i] = 0;
			vecRoundScore[i] = 0;
		}
		if (cbReason != Constants.GAME_END_DISMISS) {
			{
				SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
				cmd.lShuiShou = realshui;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
						int byOutCardData[] = new int[5];
						m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						// 鐗屽瀷
						cmd.bCardType[i] = m_vecCardType[i];
						// 鐗屽唴瀹
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					} else {
						int byOutCardData[] = new int[5];
						cmd.bCardType[i] = 0;
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					}

				}
//				int byPowerRate1[] = { 
//						0, 1, 0, 1, 1, 1, 1, 1, 1, 2,
//						2, 2, 3, 0, 0, 0, 0, 5, 5, 5,
//						5, 5, 5, 5, 5 }; //缁忓吀鍊嶆暟
//				int byPowerRate2[] = { 0, 1, 0, 1, 2,
//						3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 15, 16, 17 ,18,19,20,25,25};//鐤媯鍔犲
				
				// 经典模式倍数
				int byScoreMode1[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	1, 		 	// 牛2 		4
                	1, 		 	// 牛3 		5
                	1, 		 	// 牛4 		6
                	1, 		 	// 牛5 		7
                	1, 		 	// 牛6 		8
                	2, 		 	// 牛7 		9
                	2, 		 	// 牛8 		10
                	2, 		 	// 牛9 		11
                	3, 		 	// 牛牛 		12
                	1,			//			13
                	1,			//			14
                	4,			//银牛		15
                	1, 			//			16
                	4,			// 顺子 		17 
                	4,			// 同花牛 		18
                	4,			// 葫芦牛 		19
                	5,  		// 五小牛   	20
                	5, 			// 五花牛		21
                	5,  		// 炸弹牛 		22
                	5, 			//同花顺  		23
                	5   		//同花顺   		24
				};

				// 疯狂模式倍数
				int byScoreMode2[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	2, 		 	// 牛2 		4
                	2, 		 	// 牛3 		5
                	2, 		 	// 牛4 		6
                	3, 		 	// 牛5 		7
                	3, 		 	// 牛6 		8
                	3, 		 	// 牛7 		9
                	4, 		 	// 牛8 		10
                	4, 		 	// 牛9 		11
                	4, 		 	// 牛牛 		12
                	1,			// 			13
                	1,			// 			14
                	5,			// 			15
                	1, 			// 			16
                	5,			//	顺子 		17 
                	6,			//	同花牛	18
                	6,			//	葫芦牛	19
                	7,  		//	五小牛	20
                	8, 			//	五花牛	21
                	9,  		//	炸弹牛	22
                	10, 		//	同花顺  	23
                	10   		//  同花顺   	24
				};
				
				int byPowerRate[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
				if(m_scoreMode.equalsIgnoreCase("JINGDIANMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode1,25);
				}
				if(m_scoreMode.equalsIgnoreCase("FENGKUANGMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode2,25);
				}	

				boolean bAllWin = true;  //通杀判断
				boolean bAllFail = true; // 通赔判断
				
				//扣税赢家扣除的时候扣除庄家跟赢了的闲家的
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}

					if(m_kouShuiMode.equals("no"))
						continue;
					if(i == m_byZhuang){
						//庄家都扣税
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserRmb -= shui;
						user.getRmb1v1(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason5);
							this.addEatNormalScore(shui);
							handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
							UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
						//闲家赢
						if(m_kouShuiMode.equals("lose")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserRmb -= shui;
						user.getRmb1v1(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserRmbChange.handleRmbChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
							UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if(m_vecCardType[i] < m_vecCardType[m_byZhuang]){
						//闲家输
						if(m_kouShuiMode.equals("win")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserRmb -= shui;
						user.getRmb1v1(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserRmbChange.handleRmbChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
							UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 5, m_bTableCardArray[i], 5,
							0) == 1) {
						//闲家赢了
						if(m_kouShuiMode.equals("lose")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserRmb -= shui;
						user.getRmb1v1(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserRmbChange.handleRmbChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
							UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else{
						//闲家输了
						if(m_kouShuiMode.equals("win")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserRmb -= shui;
						user.getRmb1v1(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason5);
							this.addEatNormalScore(shui);
							handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
							UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}
				}
				//庄家
				SecShmUser zhuangUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[m_byZhuang].dwUserID);
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					
					if (12 == m_vecCardType[i]) {
						// 统计牛牛的次数
						m_niuNiuNumArray[i] ++; 
					}

					if (m_vecCardType[i] < 3) {
						// 统计无牛的次数
						m_noHaveNiuNumArray[i] ++; 
					}

					if (i != m_byZhuang) {
						int Multiple = 0;
						if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
							//闲家赢
							double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_doubleDiFen;

							BigDecimal b = new BigDecimal(rmb);
							rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
							if(rmb > zhuangUser.getRmb1v1(0)){
								//校验下rmb的数量
								rmb = zhuangUser.getRmb1v1(0);
							}

							vecRoundScore[m_byZhuang] -= rmb;
							vecRoundScore[i] += rmb;

							m_doubleVecResultScore[m_byZhuang] -= rmb;
							m_doubleVecResultScore[i] += rmb;
							m_pIUserItem[i].lUserScore += rmb;
							m_pIUserItem[m_byZhuang].lUserScore -= rmb;
							
							//记录
							m_pIUserItem[i].lUserRmb += rmb;
							m_pIUserItem[m_byZhuang].lUserRmb -= rmb;
							
							zhuangUser.getRmb1v1(0 - rmb);
							xianUser.getRmb1v1(rmb);
							UserRmbChange.handleRmbChangeWinLose(zhuangUser,-rmb, UserGoldChange.reason15);
							UserRmbChange.handleRmbChangeWinLose(xianUser,rmb,UserGoldChange.reason15);
							
							m_winNumArray[i] ++;
							bAllWin = false;
							if(m_pIUserItem[i].isAndroidUser == 2){
								//robot win & lost
								this.addRobotWinScore(rmb);
							}
						} else if (m_vecCardType[i] < m_vecCardType[m_byZhuang]) {
							//庄家赢了
							double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_doubleDiFen;

							BigDecimal b = new BigDecimal(rmb);
							rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
							if(rmb > xianUser.getRmb1v1(0)){
								//校验下rmb的数量
								rmb = xianUser.getRmb1v1(0);
							}
							vecRoundScore[m_byZhuang] += rmb;
							vecRoundScore[i] -= rmb;

							m_doubleVecResultScore[m_byZhuang] += rmb;
							m_doubleVecResultScore[i] -= rmb;

							m_pIUserItem[i].lUserScore -= rmb;
							m_pIUserItem[m_byZhuang].lUserScore += rmb;
							
							//记录
							m_pIUserItem[i].lUserRmb -= rmb;
							m_pIUserItem[m_byZhuang].lUserRmb += rmb;
							zhuangUser.getRmb1v1(rmb);
							xianUser.getRmb1v1(0 - rmb);
							UserRmbChange.handleRmbChangeWinLose(zhuangUser,rmb, UserRmbChange.reason15);
							UserRmbChange.handleRmbChangeWinLose(xianUser,-rmb,UserRmbChange.reason15);
							
							m_winNumArray[m_byZhuang] ++;
							bAllFail = false;
							if(m_pIUserItem[i].isAndroidUser == 2){
								//robot win & lost
								this.addRobotWinScore(-rmb);
							}
						} else {
							if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 5, m_bTableCardArray[i], 5,
									Multiple) == 1) {
								//闲家赢了
								double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_doubleDiFen;

								BigDecimal b = new BigDecimal(rmb);
								rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
								if(rmb > zhuangUser.getRmb1v1(0)){
									//校验下rmb的数量
									rmb = zhuangUser.getRmb1v1(0);
								}

								vecRoundScore[m_byZhuang] -= rmb;
								vecRoundScore[i] += rmb;

								m_doubleVecResultScore[m_byZhuang] -= rmb;
								m_doubleVecResultScore[i] += rmb;
								m_pIUserItem[i].lUserScore += rmb;
								m_pIUserItem[m_byZhuang].lUserScore -= rmb;
								
								//记录
								m_pIUserItem[i].lUserRmb += rmb;
								m_pIUserItem[m_byZhuang].lUserRmb -= rmb;
								zhuangUser.getRmb1v1(0 - rmb);
								xianUser.getRmb1v1(rmb);
								UserRmbChange.handleRmbChangeWinLose(zhuangUser,-rmb, UserRmbChange.reason15);
								UserRmbChange.handleRmbChangeWinLose(xianUser,rmb,UserRmbChange.reason15);

								m_winNumArray[i] ++;
								bAllWin = false;
								if(m_pIUserItem[i].isAndroidUser == 2){
									//robot win & lost
									this.addRobotWinScore(rmb);
								}
							} else {
								//庄家赢家了
								double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_doubleDiFen;
								BigDecimal b = new BigDecimal(rmb);
								rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
								if(rmb > xianUser.getRmb1v1(0)){
									//校验下rmb的数量
									rmb = xianUser.getRmb1v1(0);
								}
								vecRoundScore[m_byZhuang] += rmb;
								vecRoundScore[i] -= rmb;

								m_doubleVecResultScore[m_byZhuang] += rmb;
								m_doubleVecResultScore[i] -= rmb;

								m_pIUserItem[i].lUserScore -= rmb;
								m_pIUserItem[m_byZhuang].lUserScore += rmb;
								
								//记录
								m_pIUserItem[i].lUserRmb -= rmb;
								m_pIUserItem[m_byZhuang].lUserRmb += rmb;
								zhuangUser.getRmb1v1(rmb);
								xianUser.getRmb1v1(0 - rmb);
								UserRmbChange.handleRmbChangeWinLose(zhuangUser,rmb, UserRmbChange.reason15);
								UserRmbChange.handleRmbChangeWinLose(xianUser,-rmb,UserRmbChange.reason15);
								
								m_winNumArray[m_byZhuang] ++;
								bAllFail = false;
								if(m_pIUserItem[i].isAndroidUser == 2){
									//robot win & lost
									this.addRobotWinScore(-rmb);
								}
							}
						}
					} else {

					}
				}
				//扣赢的
				if(this.inHall() && m_kouChuMode == 0 && m_dwcKouYing != 0 && m_dwcKouYingRate > 0){
					for(int i = 0;i < 10;i++){
						//不区别机器人还是真人
						if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
							continue;
						}
						//只扣赢家的，输家输的不变
						if(vecRoundScore[i] > 0){
							double kou = vecRoundScore[i] * m_dwcKouYingRate;
							BigDecimal b = new BigDecimal(kou);
							kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
							//再次扣除需要
							xianUser.getRmb1v1(0 - kou);
							vecRoundScore[i] -= kou;
							m_doubleVecResultScore[i] -= kou;
							m_pIUserItem[i].lUserRmb -= kou;
							UserRmbChange.handleRmbChangeWinLose(xianUser,0 - kou, UserRmbChange.reason15);
							if(m_pIUserItem[i].isAndroidUser == 0){
								//只记录真人的
								UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
								double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
								double giveagent = m_dwcKouYingFanliRate * kou;
								BigDecimal b1 = new BigDecimal(givesys);
								givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								BigDecimal b2 = new BigDecimal(giveagent);
								giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
								DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason15, givesys);
							}
						}
					}
				}

				boolean isYeJi = true;
				if(m_byMaxRound == 88 && this.inUserClub()){
					for(int i = 0;i < 10;i++){
						m_doubleKouWinResultScore[i] += vecRoundScore[i];
					}
					this.m_kouWinCurrJu++;
					if(this.m_kouWinSumJu == this.m_kouWinCurrJu){
						//扣除业绩
						for(int i = 0;i < 10;i++){
							if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
								continue;
							}
							//只扣赢家的，输家输的不变
							if(m_doubleKouWinResultScore[i] > 0){
								double kou = m_doubleKouWinResultScore[i] * m_dwcKouYingRate;
								BigDecimal b = new BigDecimal(kou);
								kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								m_doubleVecResultScore[i] -= kou;

								SecShmUser safeuser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
								m_pIUserItem[i].lUserRmb -= kou;
								safeuser.getRmb1v1(0 - kou);
								
								if(m_pIUserItem[i].isAndroidUser == 0){
									//只记录真人的
									UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
									double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
									double giveagent = m_dwcKouYingFanliRate * kou;
									BigDecimal b1 = new BigDecimal(givesys);
									givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
									BigDecimal b2 = new BigDecimal(giveagent);
									giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
									UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
									DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason18, givesys);
								}
							}
						}
						this.m_kouWinCurrJu = 0;
						for(int i = 0;i < 10;i++){
							if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
								continue;
							}
							m_doubleKouWinResultScore[i] = 0.0;
						}
					}else{
						isYeJi = false;
					}
				}
				if(m_kouChuMode == 1){
					isYeJi = false;
				}
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID <= 0) {
						continue;
					}
					if(this.isDwcType()){
						cmd.lUserCoin[i] = m_pIUserItem[i].lUserRmb;
					}else if(this.isGoldType()){
						cmd.lUserCoin[i] = m_pIUserItem[i].lUserCoin;
					}
				}
				if(bAllWin){
					m_allWinArray[m_byZhuang] ++;
				}

				if (bAllFail) {
					m_allFailArray[m_byZhuang] ++;
				}

				//广播
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					if(vecRoundScore[i] > GoldMgr.getInstance().getRmbBroadCastLimit()){
						//大于进行广播
						net.sf.json.JSONObject broad = new net.sf.json.JSONObject();
						broad.put("command","public_logic_broad_user");
						broad.put("value1", m_pIUserItem[i].szNickName);
						broad.put("value2", "经典牛牛");
						broad.put("value3", vecRoundScore[i]);
						broad.put("value4", m_GameLogic.GetCardStringType(m_bTableCardArray[i], 5));
						AdminRedis.getInstance().pubAdminSubMsg(broad);
					}
				}
				//加入业绩
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					if(m_pIUserItem[i].isAndroidUser == 0 && isYeJi){
						//20局不计算业绩
						UserRedisInfo.addYeJiFanXian(m_pIUserItem[i].dwUserID,Math.abs(vecRoundScore[i]),m_clubOwnerId);
					}
				}
				for (int i = 0; i < 10; i++) {
					cmd.nRoundScore[i] = vecRoundScore[i];
					cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
					
					for(int j = 0; j < 5; j ++)
					{
						if(0 != m_vecXuanPaiCardList[i][j])
						{
							cmd.bCardData[i][j] = m_vecXuanPaiCardList[i][j];
						}
					}
				}

				// 记录每一局牌、牌型、分数
				NNRoundRecord objRecord = new NNRoundRecord();
				for (int i = 0; i < 10 ;i ++ ) {
					if(m_pIUserItem[i].cbUserStatus > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus){
						objRecord.m_vecReport_CardType[i] = m_vecCardType[i];
						objRecord.m_vecReport_Score[i] = vecRoundScore[i];
						objRecord.m_vecReport_XiaZhu[i] = m_byXiaZhu[i];
						objRecord.m_names[i] = m_pIUserItem[i].szNickName;
						for (int j = 0; j < 5; j ++) {
							objRecord.m_vecReport_CardData[i][j] = cmd.bCardData[i][j];
						}
					}
				}
				
				objRecord.m_vecReport_Zhunag = m_byZhuang;
				m_vecRoundRecord[m_byRound - 2] = objRecord;
				
				SUBCMD_S_ROUND_RECORD cmd_record = new SUBCMD_S_ROUND_RECORD();
				cmd_record.m_vecRecordRoundPai = objRecord.m_vecReport_CardData;
				cmd_record.m_vecRecordRoundScore = objRecord.m_vecReport_Score;
				cmd_record.m_vecRecordRoundCardType = objRecord.m_vecReport_CardType;
				cmd_record.m_vecRecordRoundXiazhu = objRecord.m_vecReport_XiaZhu;
				cmd_record.m_nZhuang = m_byZhuang;
				cmd_record.m_nRound = m_byRound - 2;
				cmd_record.m_name = objRecord.m_names;

				System.out.printf("%n--- NIUNIU LOG : tableId: %s %n wanfa: %s",m_dwTableID,m_strParam);
				SendData(Constants.INVALID_CHAIR, cmd_record.getJsonData());
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}

		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);
		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound >= m_byMaxRound){
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getDwcJuShu(1);
					}
				}
			}
			m_byRound = m_byRound<m_byMaxRound?m_byRound:m_byMaxRound;	
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;
			if(m_kouChuMode == 1){
				//模式为结算扣除，开始扣除
				for(int i = 0;i < 10;i++){
					//不区别机器人还是真人
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					//只扣赢家的，输家输的不变
					if(m_doubleVecResultScore[i] > 0){
						double kou = m_doubleVecResultScore[i] * m_dwcKouYingRate;
						BigDecimal b = new BigDecimal(kou);
						kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//再次扣除需要
						m_doubleVecResultScore[i] -= kou;
						xianUser.getRmb1v1(0 - kou);
						UserRmbChange.handleRmbChangeWinLose(xianUser,0 - kou, UserRmbChange.reason15);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//只记录真人的
							UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
							double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
							double giveagent = m_dwcKouYingFanliRate * kou;
							BigDecimal b1 = new BigDecimal(givesys);
							givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							BigDecimal b2 = new BigDecimal(giveagent);
							giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
							DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason15, givesys);
						}
					}
				}
			}
			for (int k = 0; k < 10; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_doubleVecResultScore[k];

				cmd.m_vecAllWinNum[k] = m_allWinArray[k];
				cmd.m_vecAllFailNum[k] = m_allFailArray[k];
				cmd.m_vecNiuNiuNum[k] = m_niuNiuNumArray[k];
				cmd.m_vecNoNiuNum[k] = m_noHaveNiuNumArray[k];
				cmd.m_vecWinNum[k] = m_winNumArray[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			m_bTableStarted = false;
			for (int i = 0; i < 10; i++) {// 娓呴櫎鐗屽眬鏁版嵁
				m_vecResultScore[i] = 0;
			}

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);
		}	
	}
	void onEventGameEndGold(int bySeatID,int cbReason){
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 0;

		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				cntUser++;
			}
		}
		m_aiRobotDelay = (int) (4 + CommonDef.getRandomInt(3) + cntUser * 1);
		double shuishourate = getShuiShou(this.GetType());
		int shui = (int) (this.m_difen * shuishourate);
		double[] realshui = new double[10];
		for(int i = 0;i < 10;i++){
			realshui[i] = 0;
		}
		if (cbReason != Constants.GAME_END_DISMISS) {
			{
				SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
				cmd.lShuiShou = realshui;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
						int byOutCardData[] = new int[5];
						m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						// 鐗屽瀷
						cmd.bCardType[i] = m_vecCardType[i];
						// 鐗屽唴瀹
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					} else {
						int byOutCardData[] = new int[5];
						cmd.bCardType[i] = 0;
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					}

				}
//				int byPowerRate1[] = { 
//						0, 1, 0, 1, 1, 1, 1, 1, 1, 2,
//						2, 2, 3, 0, 0, 0, 0, 5, 5, 5,
//						5, 5, 5, 5, 5 }; //缁忓吀鍊嶆暟
//				int byPowerRate2[] = { 0, 1, 0, 1, 2,
//						3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 15, 16, 17 ,18,19,20,25,25};//鐤媯鍔犲
				
				// 经典模式倍数
				int byScoreMode1[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	1, 		 	// 牛2 		4
                	1, 		 	// 牛3 		5
                	1, 		 	// 牛4 		6
                	1, 		 	// 牛5 		7
                	1, 		 	// 牛6 		8
                	2, 		 	// 牛7 		9
                	2, 		 	// 牛8 		10
                	2, 		 	// 牛9 		11
                	3, 		 	// 牛牛 		12
                	1,			//			13
                	1,			//			14
                	4,			//银牛		15
                	1, 			//			16
                	4,			// 顺子 		17 
                	4,			// 同花牛 		18
                	4,			// 葫芦牛 		19
                	5,  		// 五小牛   	20
                	5, 			// 五花牛		21
                	5,  		// 炸弹牛 		22
                	5, 			//同花顺  		23
                	5   		//同花顺   		24
				};

				// 疯狂模式倍数
				int byScoreMode2[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	2, 		 	// 牛2 		4
                	2, 		 	// 牛3 		5
                	2, 		 	// 牛4 		6
                	3, 		 	// 牛5 		7
                	3, 		 	// 牛6 		8
                	3, 		 	// 牛7 		9
                	4, 		 	// 牛8 		10
                	4, 		 	// 牛9 		11
                	4, 		 	// 牛牛 		12
                	1,			// 			13
                	1,			// 			14
                	5,			// 			15
                	1, 			// 			16
                	5,			//	顺子 		17 
                	6,			//	同花牛	18
                	6,			//	葫芦牛	19
                	7,  		//	五小牛	20
                	8, 			//	五花牛	21
                	9,  		//	炸弹牛	22
                	10, 		//	同花顺  	23
                	10   		//  同花顺   	24
				};
				
				int byPowerRate[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
				if(m_scoreMode.equalsIgnoreCase("JINGDIANMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode1,25);
				}
				if(m_scoreMode.equalsIgnoreCase("FENGKUANGMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode2,25);
				}	

				boolean bAllWin = true;  //通杀判断
				boolean bAllFail = true; // 通赔判断
				
				//扣税赢家扣除的时候扣除庄家跟赢了的闲家的
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					
					if(i == m_byZhuang){
						//庄家都扣税
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserCoin -= shui;
						user.getCoin(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
						//闲家赢
						if(m_kouShuiMode.equals("lose")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserCoin -= shui;
						user.getCoin(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if(m_vecCardType[i] < m_vecCardType[m_byZhuang]){
						//闲家输
						if(m_kouShuiMode.equals("win")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserCoin -= shui;
						user.getCoin(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 5, m_bTableCardArray[i], 5,
							0) == 1) {
						//闲家赢了
						if(m_kouShuiMode.equals("lose")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserCoin -= shui;
						user.getCoin(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}else{
						//闲家输了
						if(m_kouShuiMode.equals("win")){
							continue;
						}
						SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
						realshui[i] = shui;
						m_pIUserItem[i].lUserCoin -= shui;
						user.getCoin(0 - shui);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//正常用户
							UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason5);
							this.addEatNormalScore(shui);
							handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
						}else if(m_pIUserItem[i].isAndroidUser == 2){
							//机器人
							this.addEatRobotScore(shui);
						}
					}
				}
				//庄家
				SecShmUser zhuangUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[m_byZhuang].dwUserID);
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					
					if (12 == m_vecCardType[i]) {
						// 统计牛牛的次数
						m_niuNiuNumArray[i] ++; 
					}

					if (m_vecCardType[i] < 3) {
						// 统计无牛的次数
						m_noHaveNiuNumArray[i] ++; 
					}

					if (i != m_byZhuang) {
						int Multiple = 0;
						if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
							//闲家赢
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_difen;
							if(coin > zhuangUser.getCoin(0)){
								//校验下coin的数量
								coin = zhuangUser.getCoin(0);
							}

							m_vecRoundScore[m_byZhuang] -= coin;
							m_vecRoundScore[i] += coin;

							m_vecResultScore[m_byZhuang] -= coin;
							m_vecResultScore[i] += coin;
							m_pIUserItem[i].lUserScore += coin;
							m_pIUserItem[m_byZhuang].lUserScore -= coin;
							
							//记录
							m_pIUserItem[i].lUserCoin += coin;
							m_pIUserItem[m_byZhuang].lUserCoin -= coin;
							
							zhuangUser.getCoin(0 - coin);
							xianUser.getCoin(coin);
							UserGoldChange.handleGoldChangeWinLose(zhuangUser,coin, UserGoldChange.reason15);
							UserGoldChange.handleGoldChangeWinLose(xianUser,coin,UserGoldChange.reason15);
							
							m_winNumArray[i] ++;
							bAllWin = false;
							if(m_pIUserItem[i].isAndroidUser == 2){
								//robot win & lost
								this.addRobotWinScore(coin);
							}
						} else if (m_vecCardType[i] < m_vecCardType[m_byZhuang]) {
							//庄家赢了
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_difen;
							if(coin > xianUser.getCoin(0)){
								coin = Math.abs(xianUser.getCoin(0));
							}
							m_vecRoundScore[m_byZhuang] += coin;
							m_vecRoundScore[i] -= coin;

							m_vecResultScore[m_byZhuang] += coin;
							m_vecResultScore[i] -= coin;

							m_pIUserItem[i].lUserScore -= coin;
							m_pIUserItem[m_byZhuang].lUserScore += coin;
							
							//记录
							m_pIUserItem[i].lUserCoin -= coin;
							m_pIUserItem[m_byZhuang].lUserCoin += coin;
							zhuangUser.getCoin(coin);
							xianUser.getCoin(0 - coin);
							UserGoldChange.handleGoldChangeWinLose(zhuangUser,coin, UserGoldChange.reason15);
							UserGoldChange.handleGoldChangeWinLose(xianUser,coin,UserGoldChange.reason15);
							
							m_winNumArray[m_byZhuang] ++;
							bAllFail = false;
							if(m_pIUserItem[i].isAndroidUser == 2){
								//robot win & lost
								this.addRobotWinScore(coin);
							}
						} else {
							if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 5, m_bTableCardArray[i], 5,
									Multiple) == 1) {
								//闲家赢了
								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_difen;
								if(coin > zhuangUser.getCoin(0)){
									coin = zhuangUser.getCoin(0);
								}

								m_vecRoundScore[m_byZhuang] -= coin;
								m_vecRoundScore[i] += coin;

								m_vecResultScore[m_byZhuang] -= coin;
								m_vecResultScore[i] += coin;
								m_pIUserItem[i].lUserScore += coin;
								m_pIUserItem[m_byZhuang].lUserScore -= coin;
								
								//记录
								m_pIUserItem[i].lUserCoin += coin;
								m_pIUserItem[m_byZhuang].lUserCoin -= coin;
								zhuangUser.getCoin(0 - coin);
								xianUser.getCoin(coin);
								UserGoldChange.handleGoldChangeKouShui(zhuangUser,coin, UserGoldChange.reason15);
								UserGoldChange.handleGoldChangeKouShui(xianUser,coin,UserGoldChange.reason15);

								m_winNumArray[i] ++;
								bAllWin = false;
								if(m_pIUserItem[i].isAndroidUser == 2){
									//robot win & lost
									this.addRobotWinScore(coin);
								}
							} else {
								//庄家赢家了
								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_difen;
								if(coin > xianUser.getCoin(0)){
									coin = xianUser.getCoin(0);
								}
								m_vecRoundScore[m_byZhuang] += coin;
								m_vecRoundScore[i] -= coin;

								m_vecResultScore[m_byZhuang] += coin;
								m_vecResultScore[i] -= coin;

								m_pIUserItem[i].lUserScore -= coin;
								m_pIUserItem[m_byZhuang].lUserScore += coin;
								
								//记录
								m_pIUserItem[i].lUserCoin -= coin;
								m_pIUserItem[m_byZhuang].lUserCoin += coin;
								zhuangUser.getCoin(coin);
								xianUser.getCoin(0 - coin);
								UserGoldChange.handleGoldChangeKouShui(zhuangUser,coin, UserGoldChange.reason15);
								UserGoldChange.handleGoldChangeKouShui(xianUser,coin,UserGoldChange.reason15);
								
								m_winNumArray[m_byZhuang] ++;
								bAllFail = false;
								if(m_pIUserItem[i].isAndroidUser == 2){
									//robot win & lost
									this.addRobotWinScore(coin);
								}
							}
						}
					} else {

					}
				}

				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID <= 0) {
						continue;
					}
					cmd.lUserCoin[i] = m_pIUserItem[i].lUserCoin;
				}
				if(bAllWin){
					m_allWinArray[m_byZhuang] ++;
				}

				if (bAllFail) {
					m_allFailArray[m_byZhuang] ++;
				}

				for (int i = 0; i < 10; i++) {
					cmd.nRoundScore[i] = m_vecRoundScore[i];
					cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
					
					for(int j = 0; j < 5; j ++)
					{
						if(0 != m_vecXuanPaiCardList[i][j])
						{
							cmd.bCardData[i][j] = m_vecXuanPaiCardList[i][j];
						}
					}
				}

				// 记录每一局牌、牌型、分数
				NNRoundRecord objRecord = new NNRoundRecord();
				for (int i = 0; i < 10 ;i ++ ) {
					if(m_pIUserItem[i].cbUserStatus > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus){
						objRecord.m_vecReport_CardType[i] = m_vecCardType[i];
						objRecord.m_vecReport_Score[i] = m_vecRoundScore[i];
						objRecord.m_vecReport_XiaZhu[i] = m_byXiaZhu[i];
						
						for (int j = 0; j < 5; j ++) {
							objRecord.m_vecReport_CardData[i][j] = cmd.bCardData[i][j];
						}
					}	
				}
				
				objRecord.m_vecReport_Zhunag = m_byZhuang;
				m_vecRoundRecord[m_byRound - 2] = objRecord;
				
				SUBCMD_S_ROUND_RECORD cmd_record = new SUBCMD_S_ROUND_RECORD();
				cmd_record.m_vecRecordRoundPai = objRecord.m_vecReport_CardData;
				cmd_record.m_vecRecordRoundScore = objRecord.m_vecReport_Score;
				cmd_record.m_vecRecordRoundCardType = objRecord.m_vecReport_CardType;
				cmd_record.m_vecRecordRoundXiazhu = objRecord.m_vecReport_XiaZhu;
				cmd_record.m_name = objRecord.m_names;
				cmd_record.m_nZhuang = m_byZhuang;
				cmd_record.m_nRound = m_byRound - 2;

				System.out.printf("%n--- NIUNIU LOG : tableId: %s %n wanfa: %s",m_dwTableID,m_strParam);
				SendData(Constants.INVALID_CHAIR, cmd_record.getJsonData());
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}

		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);
		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound >= m_byMaxRound){
				for(int i = 0;i < 10;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getGoldJuShu(1);
					}
				}
			}
			m_byRound = m_byRound<m_byMaxRound?m_byRound:m_byMaxRound;	
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 10; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];

				cmd.m_vecAllWinNum[k] = m_allWinArray[k];
				cmd.m_vecAllFailNum[k] = m_allFailArray[k];
				cmd.m_vecNiuNiuNum[k] = m_niuNiuNumArray[k];
				cmd.m_vecNoNiuNum[k] = m_noHaveNiuNumArray[k];
				cmd.m_vecWinNum[k] = m_winNumArray[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			m_bTableStarted = false;
			for (int i = 0; i < 10; i++) {// 娓呴櫎鐗屽眬鏁版嵁
				m_vecResultScore[i] = 0;
			}

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);
		}	
	}
	void OnEventGameEndZuJu(int bySeatID, int cbReason) {
		m_byRound = m_byRound + 1;
		OnRoundInfoChange();
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 0;

		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				cntUser++;
			}
		}
		if (cbReason != Constants.GAME_END_DISMISS) {
			{
				SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus != Constants.US_LOOKON) {
						int byOutCardData[] = new int[5];
						m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						// 鐗屽瀷
						cmd.bCardType[i] = m_vecCardType[i];
						// 鐗屽唴瀹
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					} else {
						int byOutCardData[] = new int[5];
						cmd.bCardType[i] = 0;
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
						cmd.bCardData[i][2] = byOutCardData[2];
						cmd.bCardData[i][3] = byOutCardData[3];
						cmd.bCardData[i][4] = byOutCardData[4];
					}

				}
//				int byPowerRate1[] = { 
//						0, 1, 0, 1, 1, 1, 1, 1, 1, 2,
//						2, 2, 3, 0, 0, 0, 0, 5, 5, 5,
//						5, 5, 5, 5, 5 }; //缁忓吀鍊嶆暟
//				int byPowerRate2[] = { 0, 1, 0, 1, 2,
//						3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 15, 16, 17 ,18,19,20,25,25};//鐤媯鍔犲
				
				// 经典模式倍数
				int byScoreMode1[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	1, 		 	// 牛2 		4
                	1, 		 	// 牛3 		5
                	1, 		 	// 牛4 		6
                	1, 		 	// 牛5 		7
                	1, 		 	// 牛6 		8
                	2, 		 	// 牛7 		9
                	2, 		 	// 牛8 		10
                	2, 		 	// 牛9 		11
                	3, 		 	// 牛牛 		12
                	1,			//			13
                	1,			//			14
                	4,			//银牛		15
                	1, 			//			16
                	4,			// 顺子 		17 
                	4,			// 同花牛 		18
                	4,			// 葫芦牛 		19
                	5,  		// 五小牛   	20
                	5, 			// 五花牛		21
                	5,  		// 炸弹牛 		22
                	5, 			//同花顺  		23
                	5   		//同花顺   		24
				};

				// 疯狂模式倍数
				int byScoreMode2[] = { 
					1, 		 	//     		0
                	1, 		 	//没牛 		1
                	1, 		 	//     		2
                	1, 		 	// 牛1 		3
                	2, 		 	// 牛2 		4
                	2, 		 	// 牛3 		5
                	2, 		 	// 牛4 		6
                	3, 		 	// 牛5 		7
                	3, 		 	// 牛6 		8
                	3, 		 	// 牛7 		9
                	4, 		 	// 牛8 		10
                	4, 		 	// 牛9 		11
                	4, 		 	// 牛牛 		12
                	1,			// 			13
                	1,			// 			14
                	5,			// 			15
                	1, 			// 			16
                	5,			//	顺子 		17 
                	6,			//	同花牛	18
                	6,			//	葫芦牛	19
                	7,  		//	五小牛	20
                	8, 			//	五花牛	21
                	9,  		//	炸弹牛	22
                	10, 		//	同花顺  	23
                	10   		//  同花顺   	24
				};
				
				int byPowerRate[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
				if(m_scoreMode.equalsIgnoreCase("JINGDIANMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode1,25);
				}
				if(m_scoreMode.equalsIgnoreCase("FENGKUANGMOSHI"))
				{
					Constants.CopyMemory(byPowerRate,byScoreMode2,25);
				}	

				boolean bAllWin = true;  //通杀判断
				boolean bAllFail = true; // 通赔判断

				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}

					if (12 == m_vecCardType[i]) {
						// 统计牛牛的次数
						m_niuNiuNumArray[i] ++; 
					}

					if (m_vecCardType[i] < 3) {
						// 统计无牛的次数
						m_noHaveNiuNumArray[i] ++; 
					}

					if (i != m_byZhuang) {
						int Multiple = 0;
						if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower;

							m_vecRoundScore[m_byZhuang] -= coin;
							m_vecRoundScore[i] += coin;

							m_vecResultScore[m_byZhuang] -= coin;
							m_vecResultScore[i] += coin;
							m_pIUserItem[i].lUserScore += coin;
							m_pIUserItem[m_byZhuang].lUserScore -= coin;

							m_winNumArray[i] ++;
							bAllWin = false;
						} else if (m_vecCardType[i] < m_vecCardType[m_byZhuang]) {
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower;

							m_vecRoundScore[m_byZhuang] += coin;
							m_vecRoundScore[i] -= coin;

							m_vecResultScore[m_byZhuang] += coin;
							m_vecResultScore[i] -= coin;

							m_pIUserItem[i].lUserScore -= coin;
							m_pIUserItem[m_byZhuang].lUserScore += coin;
							
							m_winNumArray[m_byZhuang] ++;
							bAllFail = false;
						} else {
							if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 5, m_bTableCardArray[i], 5,
									Multiple) == 1) {// Next 澶 搴勮緭
								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower;

								m_vecRoundScore[m_byZhuang] -= coin;
								m_vecRoundScore[i] += coin;

								m_vecResultScore[m_byZhuang] -= coin;
								m_vecResultScore[i] += coin;
								m_pIUserItem[i].lUserScore += coin;
								m_pIUserItem[m_byZhuang].lUserScore -= coin;

								m_winNumArray[i] ++;
								bAllWin = false;
							} else {
								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower;

								m_vecRoundScore[m_byZhuang] += coin;
								m_vecRoundScore[i] -= coin;

								m_vecResultScore[m_byZhuang] += coin;
								m_vecResultScore[i] -= coin;

								m_pIUserItem[i].lUserScore -= coin;
								m_pIUserItem[m_byZhuang].lUserScore += coin;
								
								m_winNumArray[m_byZhuang] ++;
								bAllFail = false;
							}
						}
					} else {

					}
				}

				if(bAllWin){
					m_allWinArray[m_byZhuang] ++;
				}

				if (bAllFail) {
					m_allFailArray[m_byZhuang] ++;
				}

				for (int i = 0; i < 10; i++) {
					cmd.nRoundScore[i] = m_vecRoundScore[i];
					cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
					
					for(int j = 0; j < 5; j ++)
					{
						if(0 != m_vecXuanPaiCardList[i][j])
						{
							cmd.bCardData[i][j] = m_vecXuanPaiCardList[i][j];
						}
					}
				}

				// 记录每一局牌、牌型、分数
				NNRoundRecord objRecord = new NNRoundRecord();
				for (int i = 0; i < 10 ;i ++ ) {
					if(m_pIUserItem[i].cbUserStatus > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus){
						objRecord.m_vecReport_CardType[i] = m_vecCardType[i];
						objRecord.m_vecReport_Score[i] = m_vecRoundScore[i];
						objRecord.m_vecReport_XiaZhu[i] = m_byXiaZhu[i];
						
						for (int j = 0; j < 5; j ++) {
							objRecord.m_vecReport_CardData[i][j] = cmd.bCardData[i][j];
						}
					}	
				}
				
				objRecord.m_vecReport_Zhunag = m_byZhuang;
				m_vecRoundRecord[m_byRound - 2] = objRecord;
				
				SUBCMD_S_ROUND_RECORD cmd_record = new SUBCMD_S_ROUND_RECORD();
				cmd_record.m_vecRecordRoundPai = objRecord.m_vecReport_CardData;
				cmd_record.m_vecRecordRoundScore = objRecord.m_vecReport_Score;
				cmd_record.m_vecRecordRoundCardType = objRecord.m_vecReport_CardType;
				cmd_record.m_vecRecordRoundXiazhu = objRecord.m_vecReport_XiaZhu;
				cmd_record.m_name = objRecord.m_names;
				cmd_record.m_nZhuang = m_byZhuang;
				cmd_record.m_nRound = m_byRound - 2;
				
				// 大厅战绩统计
				JSONObject root = new JSONObject();
				String strRoundScore = IJsonExport.sprintf_DOUBLE(cmd_record.m_vecRecordRoundScore, 5);
				String strRoundPai = IJsonExport.sprintf_BYTE(cmd_record.m_vecRecordRoundPai, 25);
				String strRoundCardType = IJsonExport.sprintf_BYTE(cmd_record.m_vecRecordRoundCardType, 5);
				String strRoundXiazhu = IJsonExport.sprintf_BYTE(cmd_record.m_vecRecordRoundXiazhu, 5);
				
				String UIDList = "";
				String NameList = "";

				for(int i = 0; i < m_pIUserItem.length;i ++){
					if(m_pIUserItem.length - 1 != i){
						NameList += m_pIUserItem[i].szNickName + ",";
						UIDList += m_pIUserItem[i].dwUserID + ",";
					}else{
						UIDList += m_pIUserItem[i].dwUserID;
						NameList += m_pIUserItem[i].szNickName;
					}
				}
				
				root.put("scoreList", strRoundScore);
				root.put("paiList", strRoundPai);
				root.put("RoundCardType", strRoundCardType);
				root.put("RoundXiazhu", strRoundXiazhu);
				root.put("UIDList", UIDList);
				root.put("NameList", NameList);
				root.put("byRound", cmd_record.m_nRound);
				
				Replay.AddReportData(root,GetType());

				System.out.printf("%n--- NIUNIU LOG : tableId: %s %n wanfa: %s",m_dwTableID,m_strParam);
				SendData(Constants.INVALID_CHAIR, cmd_record.getJsonData());
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}

		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			QpGameMgr.getInstance().OnDismissRoom(this);

		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound >= m_byMaxRound){
				for(int i = 0;i < 10;i++){
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getZuJuJuShu(1);
					}
				}
			}
			int before_cost[] = new int[10];
			int after_cost[] = new int[10];
			int cost[] = new int[10];
			for (int i = 0; i < 10; i++) {
				cost[i] = 0;
				before_cost[i] = 0;
				after_cost[i] = 0;
			}
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if (user != null) {
						before_cost[i] = user.getGem(0);
					}
				}
			}
					
			m_byRound = m_byRound<m_byMaxRound?m_byRound:m_byMaxRound;	
			if (m_byRound > 2) {
				if (m_payWay == "FZPAY") {
//					int cost_gem = 0;
//					for (int i = 0; i < 5; i++) {
//						if (m_pIUserItem[i].dwUserID > 0) {
//							cost_gem += m_byCostGem;
//						}
//					}
//					if (m_Creator > 0) {
//						SHMUser user = dthall.getInstance().getUserInfo(m_Creator);
//						if (user != null) {
//							user.getGem(0 - cost_gem);
//						}
//					} else {
//						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[0].dwUserID);
//						if (user != null) {
//							user.getGem(0 - cost_gem);
//						}
//						cost[0] = 0 - cost_gem;
//					}
					float rate = m_byRound * 1.0f / m_byMaxRound;
					rate *= m_byCostGem;
					Float frate = new Float(rate);
					int cost_gem = frate.intValue();

					if (m_Creator > 0) {
						SHMUser user = dthall.getInstance().getUserInfo(m_Creator);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
					} else {
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[0].dwUserID);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}

						System.out.printf("%n ---- NIUNIU LOG : tableId: %d %n costGem: PayWay : FZPAY  user cost gem : %d %n wanfa: %s" ,m_dwTableID, cost_gem,m_strParam);
						cost[0] = 0 - cost_gem;
					}
					
				}
				if (m_payWay == "AAPAY") {
					float rate = m_byRound * 1.0f / m_byMaxRound;
					rate *= m_byCostGem;
					Float frate = new Float(rate);
					int cost_gem = frate.intValue();

					if (m_Creator > 0) {
						SHMUser user = dthall.getInstance().getUserInfo(m_Creator);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
					} else {
						for (int i = 0; i < 10; i++) {
							if (m_pIUserItem[i].dwUserID > 0) {
								SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
								if (user != null) {
									user.getGem(0 - cost_gem);
									cost[i] = 0 - cost_gem;

									System.out.printf("%n ---- NIUNIU LOG : tableId: %d %n costGem: payWay : AAPAY  userId:%d cost gem: %d : %n wanfa: %s" , m_dwTableID, m_pIUserItem[i].dwUserID, cost_gem,m_strParam);
								}
							}
						}
					}
//					for (int i = 0; i < 5; i++) {
//						int lFangZhu = m_pIUserItem[i].dwUserID;
//						if (lFangZhu > 0) {
//							SHMUser user = dthall.getInstance().getUserInfo(lFangZhu);
//							if (user != null) {
//								user.getGem(0 - m_byCostGem);
//								cost[i] = 0 - m_byCostGem;
//							}
//						}
//					}
				}
				if (m_payWay.equalsIgnoreCase("WINPAY")) {
					int maxUser = 5;
					int activeUser = 0;
					for(int i = 0;i < maxUser;i++){
						if (m_pIUserItem[i].dwUserID > 0){
							activeUser++;
						}
					}
					int maxcost = m_byCostGem * activeUser / maxUser;//按照实际人数
					List<Integer> winuser = new ArrayList<Integer>();
					int max = -1;
					for (int i = 0; i < maxUser; i++) {
						if (m_vecResultScore[i] > max) {
							max = m_vecResultScore[i];
						}
					}
					for (int i = 0; i < maxUser; i++) {
						if (m_vecResultScore[i] == max) {
							winuser.add(i);
						}
					}
					float rate = m_byRound * 1.0f / m_byMaxRound;
					if(rate > 1.0) rate = 1.0f;
					rate *= maxcost;
					Float frate = new Float(rate);
					int cost_gem = frate.intValue();
					cost_gem /= winuser.size();

					for (int i = 0; i < maxUser; i++) {
						if (m_pIUserItem[i].dwUserID > 0 && winuser.indexOf(i) != -1) {
							SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
							if (user != null) {
								user.getGem(0 - cost_gem);
								cost[i] = 0 - cost_gem;
							}
						}
					}
				}
				if (m_payWay == "CLUBPAY") {
					float rate = m_byRound * 1.0f / m_byMaxRound;
					rate *= m_byCostGem;
					Float frate = new Float(rate);
					int cost_gem = frate.intValue();
					DbInfoMgr.getInstance().costClubOwnerGem(this.m_clubOwnerId,cost_gem);
				}
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
						if (user != null) {
							after_cost[i] = user.getGem(0);
						}
					}
				}
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 10; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];

				cmd.m_vecAllWinNum[k] = m_allWinArray[k];
				cmd.m_vecAllFailNum[k] = m_allFailArray[k];
				cmd.m_vecNiuNiuNum[k] = m_niuNiuNumArray[k];
				cmd.m_vecNoNiuNum[k] = m_noHaveNiuNumArray[k];
				cmd.m_vecWinNum[k] = m_winNumArray[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			log_counter++;
			log_counter = log_counter % 100;
			Long t = System.currentTimeMillis() / 1000;
			Long battle_id = (t % 1000000) * 100 + log_counter;

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String created = df.format(new Date());
			{

				JSONObject root = new JSONObject();

				root.put("command", "save_battle_log");
				root.put("battle_id", battle_id);

				root.put("room_type", GetType());
				root.put("hallwfdesc", "");
				
				root.put("room_id", m_dwTableID);
				root.put("creator", GetCreator());
				
				root.put("jushu", m_byMaxRound);
				root.put("limitscore", 0);
				root.put("difen", 0);
				
				if (m_payWay == "WINPAY") {
					root.put("payway", 1);	
				}else if (m_payWay == "BIGWINPAY") {
					root.put("payway", 2);
				}else{
					root.put("payway", 0);
				}
				root.put("created", created);
				root.put("uid0", (int) m_pIUserItem[0].dwUserID);
				root.put("nickname0", m_pIUserItem[0].szNickName);
				root.put("score0", m_vecResultScore[0]);
				root.put("cost0", cost[0]);
				root.put("uid1", (int) m_pIUserItem[1].dwUserID);
				root.put("nickname1", m_pIUserItem[1].szNickName);
				root.put("score1", m_vecResultScore[1]);
				root.put("cost1", cost[1]);
				root.put("uid2", (int) m_pIUserItem[2].dwUserID);
				root.put("nickname2", m_pIUserItem[2].szNickName);
				root.put("score2", m_vecResultScore[2]);
				root.put("cost2", cost[2]);
				root.put("uid3", (int) m_pIUserItem[3].dwUserID);
				root.put("nickname3", m_pIUserItem[3].szNickName);
				root.put("score3", m_vecResultScore[3]);
				root.put("cost3", cost[3]);
				root.put("uid4", (int) m_pIUserItem[4].dwUserID);
				root.put("nickname4", m_pIUserItem[4].szNickName);
				root.put("score4", m_vecResultScore[4]);
				root.put("cost4", cost[4]);

				if(m_clubId != 0){
					//club
					root.put("clubid", m_clubId);
					root.put("wfdesc", m_wanFaStr);
					if(m_payWay == "CLUBPAY"){
						root.put("payway", 10);
					}
					ClubRedis.getInstance().addClubBattleLog(m_clubId,root.toString());
				}
				GameDB.getInstance().push_task(null, root);
				Replay.save(m_dwTableID, new org.json.JSONObject(root.toString()));

				try
				{
					for(int i =0;i<5;i++)
					{
						if(m_pIUserItem[i].dwUserID > 0 && cost[i] != 0)
						{
							JSONObject root_cost = new JSONObject();
							root_cost.put("command", "save_charge_log");
							root_cost.put("created", created);
							root_cost.put("uid", (int) m_pIUserItem[i].dwUserID);
							root_cost.put("before_cost", (int) before_cost[i]);
							root_cost.put("after_cost", (int) after_cost[i]);
							root_cost.put("cost", (int) cost[i]);
							root_cost.put("reason", " û " + m_pIUserItem[0].dwUserID + "          ˸ " + m_byMaxRound + "   " + m_payWay );
							root_cost.put("room_id", m_dwTableID);
							
							GameDB.getInstance().push_task(null, root_cost);
						}
					}	
				}catch(Exception e)
				{
					e.printStackTrace();
				}
			}

			m_bTableStarted = false;
			for (int i = 0; i < 10; i++) {// 娓呴櫎鐗屽眬鏁版嵁
				m_vecResultScore[i] = 0;
			}

			DelayRemove();

			QpGameMgr.getInstance().OnDismissRoom(this);
			
			//澶勭悊绉垎
			/*
			if(m_byRound == m_byMaxRound){
				int score = 1;
				for(int i = 0;i < 4;i++){
					if(m_pIUserItem[i].dwUserID > 0){
						int uid = m_pIUserItem[i].dwUserID;
						UserActionActivity activity = ActivityMgr.getInstance().handleSendHuaFeiActionByPlay(uid,score,"*");
						if(activity.m_useActioned){
							RankMgr.getInstance().addUserRankScore(uid,activity.m_expGet);
						}
					}
				}
			}
			*/
		}

	}

	static int log_counter = 0;


	void OnDealQiangZhuang() {
		m_curStage = "STAGE_QIANGZHUANG";
		needDealTime = Constants.TIME_XIAZHU;
		m_aiRobotDelay = CommonDef.getRandomInt(3);

		List<Integer> vecQiangZhuang4 = new ArrayList<>();
		List<Integer> vecQiangZhuang3 = new ArrayList<>();
		List<Integer> vecQiangZhuang2 = new ArrayList<>();
		List<Integer> vecQiangZhuang1 = new ArrayList<>();
		List<Integer> qiangZhuangUser = null;
		List<Integer> vecTmpUser = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				if (m_byQiangZhuang[i] == 4) {
					vecQiangZhuang4.add(i);
				}else if(m_byQiangZhuang[i] == 3){
					vecQiangZhuang3.add(i);
				}else if(m_byQiangZhuang[i] == 2){
					vecQiangZhuang2.add(i);
				}else if(m_byQiangZhuang[i] == 1){
					vecQiangZhuang1.add(i);
				}else{
					vecTmpUser.add(i);
				}
			}
		}
		int chooseZhuang = -1;
		if(vecQiangZhuang4.size() > 0){
			chooseZhuang = vecQiangZhuang4.get(Constants.rand() % vecQiangZhuang4.size());
			qiangZhuangUser = vecQiangZhuang4;
		}else if(vecQiangZhuang3.size() > 0){
			chooseZhuang = vecQiangZhuang3.get(Constants.rand() % vecQiangZhuang3.size());
			qiangZhuangUser = vecQiangZhuang3;
		}else if(vecQiangZhuang2.size() > 0){
			chooseZhuang = vecQiangZhuang2.get(Constants.rand() % vecQiangZhuang2.size());
			qiangZhuangUser = vecQiangZhuang2;
		}else if(vecQiangZhuang1.size() > 0){
			chooseZhuang = vecQiangZhuang1.get(Constants.rand() % vecQiangZhuang1.size());
			qiangZhuangUser = vecQiangZhuang1;
		}else{
			chooseZhuang = vecTmpUser.get(Constants.rand() % vecTmpUser.size());
			m_byQiangZhuang[chooseZhuang] = 1;
			qiangZhuangUser = vecTmpUser;
		}
		
		
		SUBCMD_S_DingZhuang cmd = new SUBCMD_S_DingZhuang();
		cmd.lUid = 0;
		cmd.wChairID = 0;
		cmd.wPower = 0;
		cmd.waitTime = needDealTime;
		
		m_byZhuang = chooseZhuang;
		cmd.lUid = m_pIUserItem[m_byZhuang].dwUserID;
		cmd.wChairID = m_byZhuang;
		cmd.wPower = m_byQiangZhuang[m_byZhuang];
		for(int i = 0;i < 10;i++){
			cmd.byQiangZhuang[i] = -1;
		}
		for (int i = 0; i < qiangZhuangUser.size(); i++) {
			cmd.byQiangZhuang[i] = qiangZhuangUser.get(i);
		}
		m_wZhuangPower = m_byQiangZhuang[m_byZhuang];
		
		//随机是否送倍率
		for(int i = 0;i < 10;i++){
			if(m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
				if(CommonDef.getRandomInt(100) < GoldMgr.getInstance().get10RenNiuNiuSendBeiShuRate()){
					//有的用户没有有的用户有赠送倍率
					if(CommonDef.getRandomInt(100) > 50){
						int r = CommonDef.getRandomInt(100);
						if(CommonDef.getRandomInt(100) <= 30){
							this.m_randBeiShu = 10;
						}else if(r <= 60 ){
							this.m_randBeiShu = 20;
						}else{
							this.m_randBeiShu = 15;
						}
					}else{
						this.m_randBeiShu = 0;
					}
				}else{
					this.m_randBeiShu = 0;
				}
				cmd.sendBeiShu = this.m_randBeiShu;

				SendData(i, cmd.getJsonData());
			}
		}
		System.out.printf("%n--- NIUNIU LOG : tableId: %d OnDealQiangZhuang %n wanfa: %s",m_dwTableID,m_strParam);
	}
	// 轮庄
	int LunZhuang()
	{
		int niuIndex = 0;
		switch (m_lunZhuangRule) {
		case "WUNIUXIAZHUANG":
			niuIndex = 1;
			break;
		case "NIU1XIAZHUANG":
			niuIndex = 3;
			break;
		case "NIU2XIAZHUANG":
			niuIndex = 4;
			break;
		case "NIU3XIAZHUANG":
			niuIndex = 5;
			break;
		case "LIANGJUXIAZHUANG":
			break;
		default:
			break;
		}
		
		if(0 != niuIndex){
			// 判断上一局的庄家的牌型是否大于指定的牌型
			if (m_byRound > 1) {
				if(null != m_vecRoundRecord[m_byRound - 2] && m_vecRoundRecord[m_byRound - 2].m_vecReport_CardType[m_byZhuang] <= niuIndex)
				{
					int byNextUser = GetNextUser(m_byZhuang);
					return byNextUser;
				}
			}
		}else if("LIANGJUXIAZHUANG" == m_lunZhuangRule){
			if (m_byRound > 1 && 0 == (m_byRound - 1) % 2)
			{
				int byNextUser = GetNextUser(m_byZhuang);
				return byNextUser;
			}
		}
		
		
		return -1;
	}

	void QiangZhuang(int byZhuang)
	{
		m_curStage = "STAGE_QIANGZHUANG";
		needDealTime = Constants.TIME_XIAZHU;
		m_aiRobotDelay = CommonDef.getRandomInt(3);
		
		SUBCMD_S_DingZhuang cmd = new SUBCMD_S_DingZhuang();
		cmd.lUid = 0;
		cmd.wChairID = 0;
		cmd.wPower = 0;
		cmd.waitTime = Constants.TIME_DINGZHUANG;
		
		if (m_byQiangZhuang[byZhuang] == 0) {
			m_byQiangZhuang[byZhuang] = 1;
		}
		cmd.lUid = m_pIUserItem[byZhuang].dwUserID;
		cmd.wChairID = byZhuang;
		cmd.wPower = m_byQiangZhuang[byZhuang];

		m_byZhuang = byZhuang;		

		cmd.byQiangZhuang[byZhuang] = 1;
		
		m_wZhuangPower = 1;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());		
	}
	void OnDealXiaZhu() {
		m_curStage = "STAGE_XIAZHU";

		int default_xiazhu = 1;
//		if(m_betMode.equalsIgnoreCase("BETMODE1"))
//		{
//			default_xiazhu = 3;
//		}
//		if(m_betMode.equalsIgnoreCase("BETMODE2"))
//		{
//			default_xiazhu = 10;
//		}
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_byZhuang != i) {
				if (m_byXiaZhu[i] == 0) {
					
					SUBCMD_S_XiaZhu cmd = new SUBCMD_S_XiaZhu();
					cmd.lUid = m_pIUserItem[i].dwUserID;
					cmd.wChairID = i;
					
					if(i==m_byZhuang){
						cmd.wPower = 0;
					}else{
						m_byXiaZhu[i] = default_xiazhu;
						cmd.wPower = default_xiazhu;
					}
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
				}
			}
		}

		System.out.printf("%n--- NIUNIU LOG : tableId: %d %n wanfa: %s --msg OnDealXiaZhu",m_dwTableID,m_strParam);
	}

	int GetNextUser(int bySeatID)
	{
		int wNextUser = 0;
		for (int i = 1; i < 11; i++) {
			wNextUser = (bySeatID + i) % 10;
			if (m_pIUserItem[wNextUser].dwUserID > 0) {
				return wNextUser;
			}
			
		}
		return 0;
	}
	public long currDealTime = 0;
	void OnDealAI(float dt) {
		m_DealTime = (int) (System.currentTimeMillis() / 1000);
		if(currDealTime == 0){
			currDealTime = System.currentTimeMillis();
		}else{
			long time = System.currentTimeMillis();
			if(time - currDealTime >= 1000){
				currDealTime = time;
			}else{
				return;
			}
		}
		if (m_wFaPaiDelay > 0) {
			m_wFaPaiDelay--;
			return;
		}
		if(needDealTime > 0){
			needDealTime--;
			return;
		}
		if (m_curStage == "STAGE_FAPAI_1") 
		{
			System.out.printf("%n--- NIUNIU LOG : tableId: %d %n wanfa: %s",m_dwTableID,m_strParam);
			System.out.printf("m_zhuangMode : %s ",m_zhuangMode);
			if(m_zhuangMode.equalsIgnoreCase("LUNZHUANG"))
			{
				int byZhuang = LunZhuang();

				if (-1 != byZhuang) {
					QiangZhuang(byZhuang);
				}else{
					QiangZhuang(m_byZhuang);
				}
				
			}else if(m_zhuangMode.equalsIgnoreCase("DINGZHUANG"))
			{
				QiangZhuang(m_byZhuang);
			}else{
				OnDealQiangZhuang();
			}
		} else if (m_curStage == "STAGE_QIANGZHUANG") {
			OnDealXiaZhu();
		} else if (m_curStage == "STAGE_XIAZHU") {
			FaPai_2();
		} else if (m_curStage == "STAGE_FAPAI_2") {
			OnEventGameEnd(0, Constants.GAME_END_NORMAL);
		}
	}
	public long currDealTime1 = 0;
	public int m_aiRobotDelay = 0;
	public void OnDeal(int dt) {
		if(currDealTime1 == 0){
			currDealTime1 = System.currentTimeMillis();
		}else{
			long time = System.currentTimeMillis();
			if(time - currDealTime1 >= 1000){
				currDealTime1 = time;
			}else{
				return;
			}
		}
		if(this.isGoldType() || this.isDwcType()){
			addRobotUser();
			if(m_aiRobotDelay <= 0){
				OnDealRobot();//机器人操作
			}else{
				m_aiRobotDelay--;
			}
		}
		
		if (m_bTableStarted == true) {
			if (m_wFaPaiDelay > 0) {
				m_wFaPaiDelay--;
				return;
			}
			if (needDealTime > 0) {
				needDealTime--;
				return;
			}
			if (m_bGameStarted) {
				OnDealAI(dt);
			} else {
//				OnEventGameStart();
			}

		}
		if(m_bGameStarted){
			
		}else{
			int cntReady = 0;
			int cntOnline = 0;
			int cntOffline = 0;
			for (int i = 0; i < 10; i++) {
				if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0) {
					if (m_pIUserItem[i].cbOnline == Constants.US_OFFLINE) {
						cntOffline++;
					} else {
						cntOnline++;
					}
				}
			}
			//自动开始
			for (int wChairID = 0; wChairID < 10; wChairID++) {
				if (m_pIUserItem[wChairID].dwUserID > 0 && m_pIUserItem[wChairID].cbUserStatus == Constants.US_READY) {
					cntReady++;
				}
				if (m_wRobotSeconds[wChairID] > 0) {
					m_wRobotSeconds[wChairID]--;
				}
			}

			if (cntReady >= 2) {
				needDealTime--;
				if (cntReady == cntOnline || cntReady == GetPlayerCount() || needDealTime <= 0) {
					needDealTime = 20;
					OnEventGameStart();
				}

			} else {
				needDealTime = 20;
			}
		}
	}

	static int randRobotIndex = 999;

	void AddRobot() {
		randRobotIndex++;
		int robot_uid = randRobotIndex % 9999 + 200000;

		Vector<Integer> vecEmpty = new Vector<>();
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);

			}
		}
		if (vecEmpty.size() > 0) {
			int rand = Constants.rand(0, 10000);
			int wChairID = vecEmpty.get(Constants.rand() % vecEmpty.size());

			int vecMaleFace[] = { 1, 3, 5, 7, 9 };
			int vecFemaleFace[] = { 2, 4, 6, 8, 10 };
			m_pIUserItem[wChairID].dwUserID = robot_uid;
			m_pIUserItem[wChairID].lUserScore = 1000;
			m_pIUserItem[wChairID].wChairID = wChairID;
			m_pIUserItem[wChairID].cbGender = rand % 2;
			if (m_pIUserItem[wChairID].cbGender == 1) {
				m_pIUserItem[wChairID].dwFaceID = vecMaleFace[rand % 5];
			} else {
				m_pIUserItem[wChairID].dwFaceID = vecFemaleFace[rand % 5];
			}
			m_pIUserItem[wChairID].cbUserStatus = Constants.US_NULL;
			m_pIUserItem[wChairID].isAndroidUser = 1;
			
			m_pIUserItem[wChairID].szNickName = "USER[" + wChairID + "]";

			{
				SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();
				

				cmd.m_lUid = robot_uid;
				cmd.m_wUserChairID = m_pIUserItem[wChairID].wChairID;
				cmd.m_lUserScore = m_pIUserItem[wChairID].lUserScore;
				cmd.m_iAvatar = m_pIUserItem[wChairID].dwFaceID;
				cmd.szNickName = m_pIUserItem[wChairID].szNickName;
				cmd.szIP = "";
				cmd.m_nState = m_pIUserItem[wChairID].cbUserStatus;
				
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}
			{
				m_pIUserItem[wChairID].cbUserStatus = Constants.US_READY;

				SUBCMD_S_Ready cmd = new SUBCMD_S_Ready();
				

				cmd.m_lUid = robot_uid;
				cmd.m_wUserChairID = m_pIUserItem[wChairID].wChairID;
				cmd.m_dwTableID = m_dwTableID;
				cmd.m_byRound = m_byRound;

				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}
			m_wRobotSeconds[wChairID] = 0;
		}
	}
	public void DoAddGoldRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 10;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 10){
			setNeedRobot(false,0);
			return;
		}
		
		int robot_gold = (int) RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_difen);
		int gold = GoldMgr.getInstance().applyRobotGold(robot_gold);
		if(gold == 0){
			//申请不到足够的金币
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.m_lTotalCoin = gold;
		user.setApplyNum(gold);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Handle_onReady(robot_uid, new String[2]);					
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRmbRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 10;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 10){
			setNeedRobot(false,0);
			return;
		}
		
		double robot_rmb = RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_doubleDiFen);
		robot_rmb += Math.random() * 2;
		BigDecimal b = new BigDecimal(robot_rmb);
		robot_rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
		double rmb = GoldMgr.getInstance().applyRobotRmb(robot_rmb);
		if(rmb == 0){
			//申请不到足够rmb
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.setRMb1v1Value(rmb);
		user.setApplyNum(rmb);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Handle_onReady(robot_uid, new String[2]);					
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRobotPlayer(){
		if(m_roomType.equals("GOLD")){
			DoAddGoldRobotPlayer();
		}else if(m_roomType.equals("DWC")){
			DoAddRmbRobotPlayer();
		}
	}
	void Handle_onJoin(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 10) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
		}

		SUBCMD_S_Join cmd = new SUBCMD_S_Join();
		

		String sData = cmd.getJsonData();
		SendData(_Uid, sData);
	}

	void Handle_onReady(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 10) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
		}
		
		int cntReady = 0;
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if(m_pIUserItem[i].cbUserStatus == Constants.US_READY){
					cntReady++;
				}
				
				cntUser ++;
			}		
		}

		SUBCMD_S_Ready cmd = new SUBCMD_S_Ready();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = bySeatID;
		cmd.m_dwTableID = m_dwTableID;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		if (cntUser > 1 && cntReady == cntUser) {
			OnEventGameStart();
		} else {

		}
	}

	public void Handle_onKick(Integer lUid, String[] vecArg) {
		if (vecArg.length < 2)
			return;
		if (m_bTableStarted && m_pIUserItem[0].dwUserID == lUid) {// 已经开始 并且不是房主
			int kick_uid  = Constants.atoi(vecArg[1]);
			int seat = FindSeat(kick_uid);
			if (Constants.US_LOOKON == m_pIUserItem[seat].cbUserStatus) {
				
				SUBCMD_S_Kick cmd = new SUBCMD_S_Kick();
				cmd.m_lUid = kick_uid;
				
				String sData = cmd.getJsonData();
				SendData(Constants.INVALID_CHAIR, sData);
				
				OnUserStandUp(kick_uid,true);
				
				// 是旁观者直接踢出房间
				QpGameMgr.getInstance().OnRemoveUserRoom(kick_uid);
				
				int cntReady = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
						cntReady++;
					}
				}
				
				int cntUser = 0;
				for (int i = 0; i < 10; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
						cntUser++;
					}
				}
				
				if (cntReady == cntUser) {
					OnEventGameStart();
				}
			}
		}	
	}
	
	void Handle_InBack(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
				
		SUBCMD_S_InBack cmd = new SUBCMD_S_InBack();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}

	void Handle_InFore(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		
		SUBCMD_S_InFore cmd = new SUBCMD_S_InFore();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	void Handle_GameIap(int _Uid,String vecArg[]){
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user == null){
			return;
		}
		SUBCMD_S_GameIap cmd = new SUBCMD_S_GameIap();
		cmd.uid = _Uid;
		cmd.seat = wChairID;
		if(this.isDwcType()){
			cmd.coin = user.getRmb1v1Value();
			m_pIUserItem[wChairID].lUserRmb = cmd.coin;
		}else{
			cmd.coin = user.getCoin(0);
			m_pIUserItem[wChairID].lUserCoin = (int) cmd.coin;
		}
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	private int m_needAddRobot = 0;
	public void Handle_QuickMatch(int _Uid,String vecArg[]){
		try{
			int wChairID = FindSeat(_Uid);
			if (wChairID == Constants.INVALID_CHAIR) {
				return;
			}
			SHMUser user = dthall.getInstance().getUserInfo(_Uid);
			if(user == null){
				return;
			}
			//add robot
			class AddRobotTask extends TimerTask{
				public Timer _timer;
				@Override
				public void run() {
					if(CommonDef.getRandomInt(100) > 75)
						return;
					int rev = addRobotPlayer();
					if(rev < 0){
						_timer.cancel();
					}
				}
			}
			if(m_needAddRobot == 0)
				m_needAddRobot = 2 + CommonDef.getRandomInt(3);
			Timer timer = new Timer();
			AddRobotTask task = new AddRobotTask();
			task._timer = timer;
			timer.schedule(task,2000,3000);
		}catch(Exception e){
			
		}
	}
	public int addRobotPlayer(){
		int userCnt = 0;
		int robotCnt = 0;
		for(int i = 0;i < 10;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
			if(m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 2){
				robotCnt++;
			}
		}
		if(userCnt == 10){
			SUBCMD_S_QuickMatchFinish cmd = new SUBCMD_S_QuickMatchFinish();
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			return -1;
		}
		if(robotCnt >= m_needAddRobot){
			SUBCMD_S_QuickMatchFinish cmd = new SUBCMD_S_QuickMatchFinish();
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			return -1;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		
		int robot_gold = (int) RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_difen);
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null)
			return 0;
		user.m_lTotalCoin = robot_gold;		

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}
			// 主动准备
			Handle_onReady(robot_uid, new String[2]);
			return 1;
		}
		return 1;
	}
	public boolean isQiangZhuang(int _uid){
		
		int bySeatID = FindSeat(_uid);	
		
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0&&m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				int byOutCardData[] = new int[5];
				m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
			} 

		}
		int winNum = 0;
		int loseNum = 0;
		for(int i=0;i<10;i++){
			if(i != bySeatID&&m_pIUserItem[i].isAndroidUser==0&&m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
				if(m_vecCardType[bySeatID]>m_vecCardType[i]){
					loseNum++;
				}else{
					winNum++;
				}
			}
		}
		if(loseNum>winNum){
			return true;
		}else if(CommonDef.getRandomInt(100) > 90){
			//偶发的抢庄
			return true;
		}
		return false;
	}
	
	public boolean isJiaZhu(int _uid){
		
		int bySeatID = FindSeat(_uid);
	
		
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0&&m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				int byOutCardData[] = new int[5];
				m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
			} 

		}
	
		if(m_vecCardType[bySeatID]>m_vecCardType[m_byZhuang]){
			return true;
		}else if(m_vecCardType[bySeatID] >= m_GameLogic.CT_SPECIAL_NIU8 ){
			if(CommonDef.getRandomInt(100) > 40){
				return true;
			}else{
				return false;
			}
		}
		return false;
	}
	void OnDealRobot() {

		if (m_bTableStarted == true) {

			if (m_curStage == "STAGE_FAPAI_1") {
				if (m_zhuangMode.equalsIgnoreCase("QIANGZHUANG")) {
					for (int i = 0; i < 10; i++) {

						if (m_pIUserItem[i].dwUserID > 0
								&& m_pIUserItem[i].isAndroidUser == 2 && m_byQiangZhuang[i] == 0) {
							if(CommonDef.getRandomInt(100) > 20){
								//有几率不做操作
								continue;
							}
							if (isQiangZhuang(m_pIUserItem[i].dwUserID) == true) {
								String vecArg[] = {"" + m_pIUserItem[i].dwUserID, "qiangzhuang", "1" };
								Handle_onQiangZhuang(m_pIUserItem[i].dwUserID,
										vecArg);
							} else {
								String vecArg[] = {"" + m_pIUserItem[i].dwUserID,  "buqiangzhuang", "0" };
								Handle_onBuQiangZhuang(
										m_pIUserItem[i].dwUserID, vecArg);
							}
						}
					}
				}
			} else if (m_curStage == "STAGE_QIANGZHUANG") {
				for (int i = 0; i < 10; i++) {

					if (m_pIUserItem[i].dwUserID > 0
							&& m_pIUserItem[i].isAndroidUser == 2 && m_byXiaZhu[i] == 0) {
						if (m_byZhuang != i) {
							if(CommonDef.getRandomInt(100) > 20){
								//有几率不做操作
								continue;
							}
							int[] default_xiazhu = { 1, 2, 3 };

							if (m_betMode.equalsIgnoreCase("BETMODE0")) {
								int[] default_xiazhu1 = { 1, 2, 3 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu1, 3);
							}
							if (m_betMode.equalsIgnoreCase("BETMODE1")) {
								int[] default_xiazhu2 = { 4, 5, 6 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu2, 3);
							}
							if (m_betMode.equalsIgnoreCase("BETBIG")) {
								int[] default_xiazhu3 = { 8, 9, 10 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu3, 3);
							}

							if (isJiaZhu(m_pIUserItem[i].dwUserID) == true) {
								String power = String
										.valueOf(default_xiazhu[2]);
								String vecArg[] = { "xiazhu","" + m_byRound, power };
								Handle_onXiaZhu(m_pIUserItem[i].dwUserID,
										vecArg);
							} else {
								if(CommonDef.getRandomInt(100) > 10){
									String power = String
											.valueOf(default_xiazhu[0]);
									String vecArg[] = { "xiazhu","" + m_byRound, power };
									Handle_onXiaZhu(m_pIUserItem[i].dwUserID,
											vecArg);
								}else{
									String power = String
											.valueOf(default_xiazhu[1]);
									String vecArg[] = { "xiazhu","" + m_byRound, power };
									Handle_onXiaZhu(m_pIUserItem[i].dwUserID,
											vecArg);
								}
							}
						}
					}
				}

			} else if (m_curStage == "STAGE_FAPAI_2") {

				for (int i = 0; i < 10; i++) {

					if (m_pIUserItem[i].dwUserID > 0
							&& m_pIUserItem[i].isAndroidUser == 2 && m_byXuanNiu[i] == 0) {
						if(CommonDef.getRandomInt(100) > 80){
							//有几率不做操作
							continue;
						}
						int byOutCardData[] = new int[5];
						int type = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						String pai = "";
						for(int k = 0;k < 5;k++){
							pai += byOutCardData[k];
							if(k < 4){
								pai += ",";
							}
						}
						if(type == 1){
							String vecArg[] = { "xuanniu", "0" ,pai};
							Handle_onXuanNiu(m_pIUserItem[i].dwUserID, vecArg);
						}else{
							String vecArg[] = { "xuanniu", "1" ,pai};
							Handle_onXuanNiu(m_pIUserItem[i].dwUserID, vecArg);
						}
					}
				}
			} else if (m_curStage == "STAGE_JIESUAN") {
				if(CommonDef.getRandomInt(100) < 60){
					for (int wChairID = 0; wChairID < 10; wChairID++) {
						if (m_pIUserItem[wChairID].isAndroidUser == 2) {
							if(this.isGoldType()){
								if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
									if(m_pIUserItem[wChairID].lUserCoin < m_lichang){
										//做一个delay，更真实
										if(this.m_autoGameIapDelay > 0){
											this.m_autoGameIapDelay--;
											return;
										}else if(this.m_autoGameIapDelay == 0){
											this.m_autoGameIapDelay = 10;
										}
										int [] applylist = {18888 + 2188,18888 + 2188,28888 + 2188,28888 + 2188,188888 + 2188,288888 + 2188,m_lichang + 1888};
										int applynum = 0;
										while(applynum < m_lichang){
											applynum = applylist[(int) (Math.random() * applylist.length)];
										}
										int gold = GoldMgr.getInstance().applyRobotGold(applynum);
										if(gold == 0.0){
											boolean hasdissmisstry = false;
											for(int k = 0;k < 10;k++){
												if(k == wChairID){
													continue;
												}
												if(m_byAgreeDismiss[k] == 1){
													hasdissmisstry = true;
												}
											}
											if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
												String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
												Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
											}
											return;
										}else{
											SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
											m_pIUserItem[wChairID].lUserCoin += gold;
											user.addApplyNum(gold);
											user.getCoin(gold);
											Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}else{
										if(CommonDef.getRandomInt(100) < 70){
											Handle_onReady(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}
								}
							}else if(this.isDwcType()){
								if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
									if(m_pIUserItem[wChairID].lUserRmb < m_lichang){
										//做一个delay，更真实
										if(this.m_autoGameIapDelay > 0){
											this.m_autoGameIapDelay--;
											return;
										}else if(this.m_autoGameIapDelay == 0){
											this.m_autoGameIapDelay = 10;
										}
										double [] applylist = {49.0,49.0,49.0,199.0,100.0,499.0,1299.0,1000.0,2000.0,m_lichang + 99.0};
										double applynum = 0.0;
										while(applynum < m_doubleDiFen){
											applynum = applylist[(int) (Math.random() * applylist.length)];
										}
										double rmb = GoldMgr.getInstance().applyRobotRmb(applynum);
										if(rmb == 0.0){
											boolean hasdissmisstry = false;
											for(int k = 0;k < 10;k++){
												if(k == wChairID){
													continue;
												}
												if(m_byAgreeDismiss[k] == 1){
													hasdissmisstry = true;
												}
											}
											if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
												String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
												Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
											}
											return;
										}else{
											SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
											m_pIUserItem[wChairID].lUserRmb += rmb;
											user.addApplyNum(rmb);
											user.addRmb1v1Value(rmb);
											Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}else{
										if(CommonDef.getRandomInt(100) < 70){
											Handle_onReady(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}
								}
							}
						}
					}
				}
			}
		} else {

		}

	}
	void Handle_onRobot(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 10) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
		}
		int cntPlayer = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		if (cntPlayer < 10) {
			for (int i = 0; i < 10 - cntPlayer; i++) {
				AddRobot();
			}
		}
	}

	// 琛ㄦ儏
	void Handle_onBiaoQing(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iBiaoQingIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}
	void Handle_onText(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if(wChairID==Constants.INVALID_CHAIR){
			return;
		}
		String strContent = vecArg[1];
		String iter = dthall.getInstance().m_mapAvatar.get(_Uid);				
		
		String szAvatarURL = "http://lamj.qilehuyu.cn/liuan-80.png";

		if(!StringUtils.isEmpty(iter)){
			m_vecInputWenZi+=iter+";"+_Uid+";"+strContent+",";
		}
		else{
			m_vecInputWenZi+=szAvatarURL+";"+_Uid+";"+strContent+",";
		}
		strContent = string_replace(strContent, "|", ".");
		strContent = string_replace(strContent, "#", ".");
		strContent = string_replace(strContent, ",", ".");
		strContent = string_replace(strContent, "\\", ".");
		strContent = string_replace(strContent, "'", ".");
		strContent = string_replace(strContent, "\"", ".");

		SUBCMD_S_Text cmd = new SUBCMD_S_Text();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.szContent = strContent;
		cmd.InputWenZi=m_vecInputWenZi;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());      
		
		if(this.isGoldType() && m_pIUserItem[wChairID].isAndroidUser == 0){
			for(int i = 0;i < 10;i++){
				if(m_pIUserItem[i].isAndroidUser == 2){
					if(CommonDef.getRandomInt(100) < 30){
						class SendBiaoQingTask extends TimerTask{
							int index = 0;
							int seat = 0;
							int uid = 0;
							@Override
							public void run() {
								// TODO Auto-generated method stub
								SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
								cmd.m_lUid = uid;
								cmd.m_wUserChairID = seat;
								cmd.m_iBiaoQingIndex = index;
								SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
							}
						}
						Timer timer = new Timer();
						SendBiaoQingTask task = new SendBiaoQingTask();
						task.index = 1 + CommonDef.getRandomInt(11);
						task.seat = i;
						task.uid = m_pIUserItem[i].dwUserID;
						timer.schedule(task,1000 + CommonDef.getRandomInt(4000));
						return;
					}
				}
			}
		}
	}
	
	
	private String string_replace(String strContent, String string, String string2) {
		return strContent.replace(string, string2);
	}
	// 璇煶
	void Handle_onYuYin(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iYuYinIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		
		if(this.isGoldType() && m_pIUserItem[wChairID].isAndroidUser == 0){
			for(int i = 0;i < 10;i++){
				if(m_pIUserItem[i].isAndroidUser == 2){
					if(CommonDef.getRandomInt(100) < 30){
						class SendBiaoQingTask extends TimerTask{
							int index = 0;
							int seat = 0;
							int uid = 0;
							@Override
							public void run() {
								// TODO Auto-generated method stub
								SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
								cmd.m_lUid = uid;
								cmd.m_wUserChairID = seat;
								cmd.m_iYuYinIndex = index;
								SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
							}
						}
						Timer timer = new Timer();
						SendBiaoQingTask task = new SendBiaoQingTask();
						task.index = 0 + CommonDef.getRandomInt(5);
						task.seat = i;
						task.uid = m_pIUserItem[i].dwUserID;
						timer.schedule(task,1000 + CommonDef.getRandomInt(4000));
						return;
					}
				}
			}
		}
	}

	// 閫佺ぜ
	void Handle_onSongLi(int _Uid, String vecArg[]) {
	}

	// 鑱婂ぉ
	void Handle_onChat(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		String strContent = vecArg[1];

		SUBCMD_S_Chat cmd = new SUBCMD_S_Chat();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.szContent = strContent;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	// 璇煶
	void Handle_onVoice(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 3)
			return;
		int seconds = Constants.atoi(vecArg[1]);
		String strVoiceURL = vecArg[2];

		SUBCMD_S_Voice cmd = new SUBCMD_S_Voice();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		cmd.szVoiceURL = strVoiceURL;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onVoiceMsg(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		float seconds = Float.parseFloat(vecArg[1]);
		
		SUBCMD_S_VoiceMsg cmd = new SUBCMD_S_VoiceMsg();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		
		cmd.data = vecArg[2];
		cmd.m_maxClip = Integer.parseInt(vecArg[3]);
		cmd.m_currClip = Integer.parseInt(vecArg[4]);
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	void Handle_onExpr(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		int uid1 = Integer.parseInt(vecArg[1]);
		int uid2 = Integer.parseInt(vecArg[2]);
		int index = Integer.parseInt(vecArg[3]);
		
		SUBCMD_S_ExprMsg cmd = new SUBCMD_S_ExprMsg();
		cmd.m_uid1 = uid1;
		cmd.m_uid2 = uid2;
		cmd.m_index = index;
		
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	// 璇煶
	void Handle_onTryDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 2)
			return;
		String attachInfo = vecArg[1];
		if(attachInfo.equals("fzquit")){
			//房主请求直接退出
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			return;
		}
		int cntUser = 0;
		int cntOnline = 0;
		int cntOffline = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2)) {
				cntUser++;
			}
		}
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2)) {
				if (m_pIUserItem[i].cbOnline == Constants.US_OFFLINE) {
					cntOffline++;
				} else {
					cntOnline++;
				}
			}
		}
		if (cntUser > 1) {
			if (m_dismissTimer == 0) {
				m_dismissTimer = Constants.time(null);
			}
			m_byAgreeDismiss[bySeatID] = 1;
			
			int cntAgree = 0;

			for (int i = 0; i < 10; i++) {
				if (m_byAgreeDismiss[i] > 0 || (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus)) {
					cntAgree++;
				}
			}
			
			if (cntAgree >= 2 && cntAgree >= cntUser - 1) {
				OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			}else{
				SUBCMD_S_TryDismissRoom cmd = new SUBCMD_S_TryDismissRoom();
				cmd.lUid = _Uid;
				cmd.dwTableID = m_dwTableID;
				cmd.szNickName = m_pIUserItem[bySeatID].szNickName;
				
				for(int i = 0; i < 10; i ++)
				{	// 旁观者不参与解散房间
					if(m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus)
					{
						SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
					}
				}
				
			
				if (cntOnline == 1) {
					OnEventGameEnd(0, Constants.GAME_END_DISMISS);
					m_dismissTimer = 0;
				}else{
					//处理robot，同意
					boolean hasRobot = false;
					for(int i = 0;i < 10;i++){
						if( m_pIUserItem[i].isAndroidUser == 2){
							hasRobot = true;
							break;
						}
					}
					if(hasRobot){
						try{
							class AgreeTask extends TimerTask{
			
								@Override
								public void run() {
									for(int i = 0;i < 10;i++){
										if( m_pIUserItem[i].isAndroidUser == 2){
											if(m_isDestoryed == false && m_byAgreeDismiss[i] == 0 && CommonDef.getRandomInt(100) > 50){
												String vecArg[] = {"agree_dismissroom","" + m_pIUserItem[i].dwUserID};
												Handle_onAgreeDismissRoom(m_pIUserItem[i].dwUserID,vecArg);
												return;
											}
										}
									}
								}					
							}
							Timer timer = new Timer();
							AgreeTask task = new AgreeTask();
							timer.schedule(task, 2000,2000);
						}catch(Exception e){
							
						}
					}
				}
			}
			
		} else {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
		}
	}

	// 璇煶
	void Handle_onAgreeDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		if (vecArg.length < 2)
			return;
		m_byAgreeDismiss[bySeatID] = 1;

		SUBCMD_S_AgreeDismissRoom cmd = new SUBCMD_S_AgreeDismissRoom();
		cmd.lUid = _Uid;
		cmd.dwTableID = m_dwTableID;
		cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

		if (bySeatID == 0 && m_bTableStarted == false) {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			return;
		}
		
		int cntAgree = 0;
		for (int i = 0; i < 10; i++) {
			if (m_byAgreeDismiss[i] > 0 || (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus)) {
				cntAgree++;
			}
		}
		
		int cntUser = 0;
		for (int i = 0; i < 10; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2) && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				cntUser++;
			}
		}
		if (cntAgree >= 2 && cntAgree >= cntUser - 1) {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
		}
	}

	// 璇煶
	void Handle_onRefuseDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		if (vecArg.length < 2)
			return;

		m_dismissTimer = 0;
		m_byAgreeDismiss[0] = 0;
		m_byAgreeDismiss[1] = 0;
		m_byAgreeDismiss[2] = 0;
		m_byAgreeDismiss[3] = 0;
		m_byAgreeDismiss[4] = 0;
		m_byAgreeDismiss[5] = 0;
		m_byAgreeDismiss[6] = 0;
		m_byAgreeDismiss[7] = 0;
		m_byAgreeDismiss[8] = 0;
		m_byAgreeDismiss[9] = 0;

		SUBCMD_S_RefuseDismissRoom cmd = new SUBCMD_S_RefuseDismissRoom();
		cmd.lUid = _Uid;
		cmd.dwTableID = m_dwTableID;
		cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onStart(int _Uid, String vecArg[]) {
		if (vecArg.length < 2)
			return;

		int bySeatID = FindSeat(_Uid);
		if (m_bTableStarted == false && bySeatID == 0 && GetPlayerCount() > 1) {
			OnEventGameStart();
		}
	}

	void Handle_onQiangZhuang(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;

		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			return;
		}

		int power = Constants.atoi(vecArg[2]);
		m_byQiangZhuang[bySeatID] = power;

		SUBCMD_S_QiangZhuang cmd = new SUBCMD_S_QiangZhuang();
		cmd.lUid = _Uid;
		cmd.wChairID = bySeatID;
		cmd.wPower = power;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

		int curNum = 0;
		int XuanZhuangN = 0;
		for (int i = 0; i < 10; i++) {
			if (m_byQiangZhuang[i] > 0 || m_byQiangZhuang[i] == -1) {
				XuanZhuangN++;
			}
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				curNum++;
			}
		}
		if (XuanZhuangN >= curNum && m_curStage == "STAGE_FAPAI_1") {
			OnDealQiangZhuang();
		}
	}

	void Handle_onBuQiangZhuang(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		m_byQiangZhuang[bySeatID] = -1;
		
		SUBCMD_S_BuQiangZhuang cmd = new SUBCMD_S_BuQiangZhuang();
		cmd.lUid = _Uid;
		cmd.wChairID = bySeatID;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		
		int curNum = 0;
		int XuanZhuangN = 0;
		for (int i = 0; i < 10; i++) {
			if (m_byQiangZhuang[i] > 0 || m_byQiangZhuang[i] == -1) {
				XuanZhuangN++;
			}
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				curNum++;
			}
		}
		
		if (XuanZhuangN >= curNum && m_curStage == "STAGE_FAPAI_1") {
			OnDealQiangZhuang();
		}

	}

	void Handle_onXiaZhu(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onXiaZhu Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		int nRound = Constants.atoi(vecArg[1]);
		int power = Constants.atoi(vecArg[2]);
		if(power > 3){
			//下注正确,只可能是10,15或者20
		}else if(power > 3){
			//不正确
			power = 1;//回复成默认值
		}
		if (m_byXiaZhu[bySeatID] == 0) {
			m_byXiaZhu[bySeatID] = power;

			SUBCMD_S_XiaZhu cmd = new SUBCMD_S_XiaZhu();
			cmd.lUid = _Uid;
			cmd.wChairID = bySeatID;
			cmd.wPower = power;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			int curNum = 0;
			int xiazhuN = 0;
			for (int i = 0; i < 10; i++) {
				if (m_byXiaZhu[i] > 0) {
					xiazhuN++;
				}
				if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
					curNum++;
				}
			}
			if (xiazhuN >= curNum - 1 && m_curStage == "STAGE_QIANGZHUANG") {
				// 鍏ㄩ儴鍑嗗濂藉彂绗簩娆＄墝
				OnDealXiaZhu();
				FaPai_2();
			}
		}

		System.out.printf("%n--- NIUNIU LOG : tableId: %d %n wanfa: %s --msg Handle_onXiaZhu",m_dwTableID,m_strParam);
	}

	void Handle_onXuanNiu(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		
		String pai = vecArg[2];
		String vecArgTanPai[] = pai.split(",");
		
		System.out.printf("%n--- NIUNIU LOG : tableId: %d  userID: %d %nHandle_onXuanNiu: %s%n wanfa: %s",
			m_dwTableID,_Uid, Arrays.toString(vecArgTanPai),m_strParam);


		for(int i = 0; i < 5; i++)
		{
			m_vecXuanPaiCardList[bySeatID][i] = Integer.parseInt(vecArgTanPai[i]); 
		}
		
		m_byXuanNiu[bySeatID] = 1;

		int curNum = 0;
		int xuanNiuN = 0;
		for (int i = 0; i < 10; i++) {
			if (m_byXuanNiu[i] > 0) {
				xuanNiuN++;
			}
			if (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus) {
				curNum++;
			}
		}
		
		SUBCMD_S_XuanNiu cmd = new SUBCMD_S_XuanNiu();
		cmd.lUid = _Uid;
		cmd.wChairID = bySeatID;
		cmd.bHaveNiu = Constants.atoi(vecArg[1]);
		
		for(int i = 0; i < 5; i++)
		{
			cmd.bCardData[i] = m_vecXuanPaiCardList[bySeatID][i]; 
		}
		
		for(int i = 0; i < 10; i ++)
		{
			if(m_pIUserItem[i].dwUserID > 0)
			{
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}
		}
		
		if (xuanNiuN >= curNum && m_curStage == "STAGE_FAPAI_2") {
			// 鍏ㄩ儴鍑嗗濂藉彂绗簩娆＄墝

			OnEventGameEnd(0, Constants.GAME_END_NORMAL);
			int cntUser = 0;
			for (int wChairID = 1; wChairID < 10; wChairID++) {
				if (m_pIUserItem[wChairID].dwUserID > 0) {
					cntUser++;
				}
			}
//			needDealTime = (cntUser * 3 + 5) / 2;
		}
	}

	public int FindSeat(int _Uid) {
		for (int bySeatID = 0; bySeatID < 10; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}

	public int m_DealTime = 0;

	public int getDealTime() {
		return m_DealTime;
	}
	
	public boolean m_bRemove = false;

	public void DelayRemove() {
		m_bRemove = true;
	}

	public void ResetKillFlag() {
		m_bRemove = false;
	}

	public boolean ShouldBeRemoved() {
		return m_bRemove;
	}
	
	public void Handle_onLock(Integer lUid, String[] vecArg) {
		
		if (vecArg.length < 2)
			return;
		if ( m_bTableStarted && m_pIUserItem[0].dwUserID == lUid) {//宸茬粡寮濮 骞朵笖鏄埧涓
			int index = Constants.atoi(vecArg[1]);
			m_locked = index;			
			
		}
	}

	@Override
	public String getRoomInfo() {
		// TODO 鑷姩鐢熸垚鐨勬柟娉曞瓨鏍
		//m_lStartTime
		//m_pIUserItem
		// m_bTableStarted;
		// m_byRound;
		// m_byMaxRound;
		//m_dwTableID
		String roomInfo = String.format("%s/%s/%s/%s/%s", 
				m_pIUserItem[0].GetUserInfo(), //#
				m_pIUserItem[1].GetUserInfo(), 
				m_pIUserItem[2].GetUserInfo(), 
				m_pIUserItem[3].GetUserInfo(),
				m_pIUserItem[4].GetUserInfo()
				);
		
		String[] vecParam = m_strParam.split(";");
		String vecParamStr = "";
		for (int i = 0; i < vecParam.length; i++) {
			String param = vecParam[i];

			if (param.equalsIgnoreCase("8JU")) {
				vecParamStr += "8灞 ";
			}
			if (param.equalsIgnoreCase("16JU")) {
				vecParamStr += "16灞 ";
			}
			if (param.equalsIgnoreCase("DINGZHUANG")) {
				
				vecParamStr += "鎴夸富鍧愬簞  ";
			}
			if (param.equalsIgnoreCase("LUNZHUANG")) {
				vecParamStr += "杞祦鍧愬簞  ";
			}
			if (param.equalsIgnoreCase("QIANGZHUANG")) {
				vecParamStr += "缁忓吀鎶㈠簞  ";
			}
			if (param.equalsIgnoreCase("BETMODE0")) {
				vecParamStr += "缁忓吀鍊嶆暟 ";
			}
			if (param.equalsIgnoreCase("BETMODE1")) {
				vecParamStr += "鐤媯鍔犲";
			}
		}
		
		int start = 0;
		if(m_bTableStarted){
			start = 1;
		}
		String descInfo = String.format("鐗涚墰 %s",vecParamStr);
		roomInfo = String.format("%s|%d|%d|%d|%s|%d|%d|%d|%s|%s", roomInfo,m_dwTableID,m_lStartTime,start,descInfo,maxPeople,m_byRound,m_byMaxRound,"鐗涚墰","NIUNIU");
		
		return roomInfo;
	}
	
	@Override
	public int getPlayerCount() {
		// TODO Auto-generated method stub
		return GetPlayerCount();
	}
	@Override
	public int getCostGem() {
		// TODO Auto-generated method stub
		return m_byCostGem;
	}
	@Override
	public int getStatus() {
		// TODO Auto-generated method stub
		if(m_bTableStarted == false)
		{
			return 0;
		}
		return 1;
	}

	@Override
	public String getRoomDesc() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getCellScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getMinScore() {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public String getPayway() {
		// TODO Auto-generated method stub
		return m_payWay;
	}

	@Override
	public String GetRoundInfo() {
		return "" + m_byRound + "/" +  m_byMaxRound;
	}
}
